From a376f0bf82065005cf89f6db4a6c9eb7341ec4b0 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 17 Oct 2020 12:47:05 +0200 Subject: [PATCH] Logger and connection improvements --- composer.json | 14 ++++++------- docs | 2 +- src/danog/MadelineProto/DataCenter.php | 11 +++++----- src/danog/MadelineProto/Db/Driver/Mysql.php | 2 ++ .../MadelineProto/Db/Driver/Postgres.php | 2 ++ src/danog/MadelineProto/Db/Driver/Redis.php | 2 ++ .../MadelineProto/Db/NullCache/MysqlArray.php | 2 ++ .../Db/NullCache/PostgresArray.php | 2 ++ .../MadelineProto/Db/NullCache/RedisArray.php | 2 ++ src/danog/MadelineProto/Logger.php | 21 ++++++++++--------- src/danog/MadelineProto/MTProto.php | 2 ++ .../MTProtoTools/CombinedUpdatesState.php | 2 ++ tools/phpdoc.php | 2 ++ 13 files changed, 43 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index 7d68653b..7e8c126f 100644 --- a/composer.json +++ b/composer.json @@ -98,13 +98,13 @@ ], "build": [ "@docs", - "@phpdocs", + "@phpdoc", "@cs-fix", "@psalm" ], - "phpdocs": [ - "@phpdocsInternal", - "@phpdocsMain" + "phpdoc": [ + "@phpdocInternal", + "@phpdocMain" ], "check": [ "@cs", @@ -115,9 +115,9 @@ "cs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff --dry-run", "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff", "psalm": "psalm", - "phpdocsMain": "php tools/phpdoc.php", - "phpdocsInternal": "phpdoc docs/docs/PHPInternal", + "phpdocMain": "php tools/phpdoc.php", + "phpdocInternal": "phpdoc docs/docs/PHPInternal", "docs": "php tools/build_docs.php", "test": "@php -dzend.assertions=1 -dassert.exception=1 ./vendor/bin/phpunit --coverage-text --config tests/phpunit.xml" } -} +} \ No newline at end of file diff --git a/docs b/docs index e15b1164..0510e69e 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit e15b11644a7e763127ed6439ac0aec84944e288e +Subproject commit 0510e69e08411194203f4034b6d4b3e3232aea75 diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index 45ada40e..7821d55f 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -365,6 +365,7 @@ class DataCenter $extra = isset($this->dclist[$test][$ipv6][$dc_number]['secret']) ? ['secret' => $this->dclist[$test][$ipv6][$dc_number]['secret']] : []; $combos[] = [[DefaultStream::class, []], [BufferedRawStream::class, []], [ObfuscatedStream::class, $extra], [IntermediatePaddedStream::class, []]]; } + $proxyCombos = []; foreach ($this->settings->getProxies() as $proxy => $extras) { if (!$dc_number && $proxy === ObfuscatedStream::class) { continue; @@ -373,7 +374,7 @@ class DataCenter if ($proxy === ObfuscatedStream::class && \in_array(\strlen($extra['secret']), [17, 34])) { $combos[] = [[DefaultStream::class, []], [BufferedRawStream::class, []], [$proxy, $extra], [IntermediatePaddedStream::class, []]]; } - foreach ($combos as $k => $orig) { + foreach ($combos as $orig) { $combo = []; if ($proxy === ObfuscatedStream::class) { $combo = $orig; @@ -386,21 +387,21 @@ class DataCenter } } else { if ($orig[1][0] === BufferedRawStream::class) { - list($first, $second) = [\array_slice($orig, 0, 2), \array_slice($orig, 2)]; + [$first, $second] = [\array_slice($orig, 0, 2), \array_slice($orig, 2)]; $first[] = [$proxy, $extra]; $combo = \array_merge($first, $second); } elseif (\in_array($orig[1][0], [WsStream::class, WssStream::class])) { - list($first, $second) = [\array_slice($orig, 0, 1), \array_slice($orig, 1)]; + [$first, $second] = [\array_slice($orig, 0, 1), \array_slice($orig, 1)]; $first[] = [BufferedRawStream::class, []]; $first[] = [$proxy, $extra]; $combo = \array_merge($first, $second); } } - \array_unshift($combos, $combo); - //unset($combos[$k]); + $proxyCombos []= $combo; } } } + $combos = array_merge($proxyCombos, $combos); if ($dc_number) { $combos[] = [[DefaultStream::class, []], [BufferedRawStream::class, []], [HttpsStream::class, []]]; } diff --git a/src/danog/MadelineProto/Db/Driver/Mysql.php b/src/danog/MadelineProto/Db/Driver/Mysql.php index a2709e3c..2c888826 100644 --- a/src/danog/MadelineProto/Db/Driver/Mysql.php +++ b/src/danog/MadelineProto/Db/Driver/Mysql.php @@ -11,6 +11,8 @@ use function Amp\Mysql\Pool; /** * MySQL driver wrapper. + * + * @internal */ class Mysql { diff --git a/src/danog/MadelineProto/Db/Driver/Postgres.php b/src/danog/MadelineProto/Db/Driver/Postgres.php index c3ff3028..af86f6e1 100644 --- a/src/danog/MadelineProto/Db/Driver/Postgres.php +++ b/src/danog/MadelineProto/Db/Driver/Postgres.php @@ -11,6 +11,8 @@ use function Amp\Postgres\Pool; /** * Postgres driver wrapper. + * + * @internal */ class Postgres { diff --git a/src/danog/MadelineProto/Db/Driver/Redis.php b/src/danog/MadelineProto/Db/Driver/Redis.php index cc71260d..a73b27b5 100644 --- a/src/danog/MadelineProto/Db/Driver/Redis.php +++ b/src/danog/MadelineProto/Db/Driver/Redis.php @@ -9,6 +9,8 @@ use danog\MadelineProto\Settings\Database\Redis as DatabaseRedis; /** * Redis driver wrapper. + * + * @internal */ class Redis { diff --git a/src/danog/MadelineProto/Db/NullCache/MysqlArray.php b/src/danog/MadelineProto/Db/NullCache/MysqlArray.php index 9e22e614..b932de6f 100644 --- a/src/danog/MadelineProto/Db/NullCache/MysqlArray.php +++ b/src/danog/MadelineProto/Db/NullCache/MysqlArray.php @@ -6,6 +6,8 @@ use danog\MadelineProto\Db\MysqlArray as DbMysqlArray; /** * MySQL database backend, no caching. + * + * @internal */ class MysqlArray extends DbMysqlArray { diff --git a/src/danog/MadelineProto/Db/NullCache/PostgresArray.php b/src/danog/MadelineProto/Db/NullCache/PostgresArray.php index 9e49ca64..a16c5626 100644 --- a/src/danog/MadelineProto/Db/NullCache/PostgresArray.php +++ b/src/danog/MadelineProto/Db/NullCache/PostgresArray.php @@ -6,6 +6,8 @@ use danog\MadelineProto\Db\PostgresArray as DbPostgresArray; /** * Postgres database backend, no caching. + * + * @internal */ class PostgresArray extends DbPostgresArray { diff --git a/src/danog/MadelineProto/Db/NullCache/RedisArray.php b/src/danog/MadelineProto/Db/NullCache/RedisArray.php index c9591f5c..318a1ec0 100644 --- a/src/danog/MadelineProto/Db/NullCache/RedisArray.php +++ b/src/danog/MadelineProto/Db/NullCache/RedisArray.php @@ -6,6 +6,8 @@ use danog\MadelineProto\Db\RedisArray as DbRedisArray; /** * Redis database backend, no caching. + * + * @internal */ class RedisArray extends DbRedisArray { diff --git a/src/danog/MadelineProto/Logger.php b/src/danog/MadelineProto/Logger.php index 72725e04..20d44cb0 100644 --- a/src/danog/MadelineProto/Logger.php +++ b/src/danog/MadelineProto/Logger.php @@ -278,15 +278,18 @@ class Logger Snitch::logFile($this->optional); $this->stdout = new ResourceOutputStream(\fopen($this->optional, 'a')); if ($maxSize !== -1) { + $optional = &$this->optional; + $stdout = &$this->stdout; $this->rotateId = Loop::repeat( 10*1000, - function () use ($maxSize) { - \clearstatcache(true, $this->optional); - if (\file_exists($this->optional) && \filesize($this->optional) >= $maxSize) { - $this->stdout = null; - \unlink($this->optional); - $this->stdout = new ResourceOutputStream(\fopen($this->optional, 'a')); - $this->logger("Automatically truncated logfile to $maxSize"); + static function () use ($maxSize, $optional, &$stdout) { + \clearstatcache(true, $optional); + if (\file_exists($optional) && \filesize($optional) >= $maxSize) { + $stdout->close(); + $stdout = null; + \unlink($optional); + $stdout = new ResourceOutputStream(\fopen($optional, 'a')); + self::log("Automatically truncated logfile to $maxSize"); } } ); @@ -303,9 +306,7 @@ class Logger } } - if (!self::$default) { - self::$default = $this; - } + self::$default = $this; if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg') { try { \error_reporting(E_ALL); diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index ad680587..6182dddd 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -52,6 +52,8 @@ use function Amp\File\size; /** * Manages all of the mtproto stuff. + * + * @internal */ class MTProto extends AsyncConstruct implements TLCallback { diff --git a/src/danog/MadelineProto/MTProtoTools/CombinedUpdatesState.php b/src/danog/MadelineProto/MTProtoTools/CombinedUpdatesState.php index 59b3513e..08371e23 100644 --- a/src/danog/MadelineProto/MTProtoTools/CombinedUpdatesState.php +++ b/src/danog/MadelineProto/MTProtoTools/CombinedUpdatesState.php @@ -21,6 +21,8 @@ namespace danog\MadelineProto\MTProtoTools; /** * Stores multiple update states. + * + * @internal */ class CombinedUpdatesState { diff --git a/tools/phpdoc.php b/tools/phpdoc.php index f864d7c6..2ed5641e 100644 --- a/tools/phpdoc.php +++ b/tools/phpdoc.php @@ -114,4 +114,6 @@ $filter = function (string $class) use ($ignore): bool { PhpDocBuilder::fromNamespace() ->setFilter($filter) ->setOutput(__DIR__.'/../docs/docs/PHP/') + ->setImage("https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png") ->run(); +