diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index ca75cb78..8e994bcf 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -138,7 +138,7 @@ class API extends InternalDoc $this->storage = $this->API->storage ?? $this->storage; unset($unserialized); - + yield from $this->API->initAsynchronously(); $this->APIFactory(); $this->logger->logger(Lang::$current_lang['madelineproto_ready'], Logger::NOTICE); @@ -182,7 +182,7 @@ class API extends InternalDoc } } /** - * Wakeup function + * Wakeup function. * * @return void */ diff --git a/src/danog/MadelineProto/APIWrapper.php b/src/danog/MadelineProto/APIWrapper.php index 1c334532..04f16686 100644 --- a/src/danog/MadelineProto/APIWrapper.php +++ b/src/danog/MadelineProto/APIWrapper.php @@ -48,14 +48,14 @@ final class APIWrapper private bool $gettingApiId = false; /** - * Web API template - * + * Web API template. + * * @var string */ private string $webApiTemplate = ''; /** - * My.telegram.org wrapper + * My.telegram.org wrapper. * * @var ?MyTelegramOrgWrapper */ @@ -69,13 +69,13 @@ final class APIWrapper private int $serialized = 0; /** - * AbstractAPIFactory instance - * + * AbstractAPIFactory instance. + * * @var AbstractAPIFactory */ private AbstractAPIFactory $factory; /** - * API wrapper + * API wrapper. * * @param API $API API instance to wrap * @param AbstractAPIFactory $factory Factory @@ -87,11 +87,11 @@ final class APIWrapper } /** - * Link two APIWrapper and API instances + * Link two APIWrapper and API instances. * * @param API|APIWrapper $a Instance to which link * @param API|APIWrapper $b Instance from which link - * + * * @return void */ public static function link($a, $b): void @@ -115,7 +115,7 @@ final class APIWrapper } /** - * Get MTProto instance + * Get MTProto instance. * * @return MTProto|null */ @@ -125,7 +125,7 @@ final class APIWrapper } /** - * Get API factory + * Get API factory. * * @return AbstractAPIFactory */ diff --git a/src/danog/MadelineProto/AbstractAPIFactory.php b/src/danog/MadelineProto/AbstractAPIFactory.php index bcf271a8..ae9296c7 100644 --- a/src/danog/MadelineProto/AbstractAPIFactory.php +++ b/src/danog/MadelineProto/AbstractAPIFactory.php @@ -70,7 +70,7 @@ abstract class AbstractAPIFactory extends AsyncConstruct */ protected function exportNamespace(string $namespace = ''): self { - $class = array_reverse(array_values(class_parents(static::class)))[3]; + $class = \array_reverse(\array_values(\class_parents(static::class)))[3]; $instance = new $class; $instance->namespace = $namespace.'.'; self::link($instance, $this); @@ -78,11 +78,11 @@ abstract class AbstractAPIFactory extends AsyncConstruct return $instance; } /** - * Link two APIFactory instances + * Link two APIFactory instances. * * @param self $a First instance * @param self $b Second instance - * + * * @return void */ protected static function link(self $a, self $b): void @@ -135,7 +135,7 @@ abstract class AbstractAPIFactory extends AsyncConstruct } } /** - * Info to dump + * Info to dump. * * @return array */ diff --git a/src/danog/MadelineProto/Async/AsyncConstruct.php b/src/danog/MadelineProto/Async/AsyncConstruct.php index 3e7e5718..2a5479c6 100644 --- a/src/danog/MadelineProto/Async/AsyncConstruct.php +++ b/src/danog/MadelineProto/Async/AsyncConstruct.php @@ -68,10 +68,10 @@ class AsyncConstruct return !$this->asyncInitPromise; } /** - * Mark instance as (de)inited forcefully + * Mark instance as (de)inited forcefully. * * @param boolean $inited Whether to mark the instance as inited or deinited - * + * * @return void */ public function forceInit(bool $inited): void diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index fea7849f..96ae8648 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -115,7 +115,7 @@ class DataCenter */ private $CookieJar; /** - * DNS connector + * DNS connector. * * @var DNSConnector */ @@ -226,7 +226,7 @@ class DataCenter $nonProxiedDoHConfig = new DoHConfig([new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'), new Nameserver('https://dns.google/resolve')]); $this->DoHClient = Magic::$altervista || Magic::$zerowebhost ? new Rfc1035StubResolver() : new Rfc8484StubResolver($DoHConfig); $this->nonProxiedDoHClient = Magic::$altervista || Magic::$zerowebhost ? new Rfc1035StubResolver() : new Rfc8484StubResolver($nonProxiedDoHConfig); - + $this->dnsConnector = new DnsConnector(new Rfc1035StubResolver()); } } diff --git a/src/danog/MadelineProto/InternalDoc.php b/src/danog/MadelineProto/InternalDoc.php index 525611f0..81af9d74 100644 --- a/src/danog/MadelineProto/InternalDoc.php +++ b/src/danog/MadelineProto/InternalDoc.php @@ -5409,6 +5409,20 @@ class InternalDoc extends APIFactory { return $this->__call(__FUNCTION__, [$obj, $var]); } + /** + * Sets a private variable in an object. + * + * @param object $obj Object + * @param string $var Attribute name + * @param mixed $val Attribute value + * + * @return mixed + * @access public + */ + public function setVar($obj, string $var, &$val): void + { + \danog\MadelineProto\MTProto::setVar($obj, $var, $val); + } /** * Discard call. * diff --git a/src/danog/MadelineProto/Loop/Generic/PeriodicLoop.php b/src/danog/MadelineProto/Loop/Generic/PeriodicLoop.php index 12b6cb66..cedc8596 100644 --- a/src/danog/MadelineProto/Loop/Generic/PeriodicLoop.php +++ b/src/danog/MadelineProto/Loop/Generic/PeriodicLoop.php @@ -30,19 +30,19 @@ use danog\MadelineProto\MTProto; class PeriodicLoop extends ResumableSignalLoop { /** - * Callback + * Callback. * * @var callable */ private $callback; /** - * Loop name + * Loop name. * * @var string */ private string $name; /** - * Loop timeeout + * Loop timeeout. * * @var int */ diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index db3ac19c..87f4bd00 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -22,7 +22,6 @@ namespace danog\MadelineProto; use Amp\Dns\Resolver; use Amp\Http\Client\DelegateHttpClient; use Amp\Loop; -use Amp\Success; use danog\MadelineProto\Async\AsyncConstruct; use danog\MadelineProto\Loop\Generic\PeriodicLoop; use danog\MadelineProto\Loop\Update\FeedLoop; @@ -840,7 +839,7 @@ class MTProto extends AsyncConstruct implements TLCallback public function __wakeup() { $backtrace = \debug_backtrace(0, 4); - $backtrace = end($backtrace); + $backtrace = \end($backtrace); $this->forceInit(false); $this->setInitPromise($this->__wakeup_async($backtrace)); } @@ -978,7 +977,7 @@ class MTProto extends AsyncConstruct implements TLCallback public static function getSettings(array $settings, array $previousSettings = []): array { Magic::classExists(); - $settings = array_replace_recursive($previousSettings, $settings); + $settings = \array_replace_recursive($previousSettings, $settings); if (isset($previousSettings['connection_settings']['default_dc'])) { $settings['connection_settings']['default_dc'] = $previousSettings['connection_settings']['default_dc']; } @@ -1243,7 +1242,7 @@ class MTProto extends AsyncConstruct implements TLCallback 'callback' => 'getUpdatesUpdateHandler', // Update callback 'run_callback' => true, - ], 'secret_chats' => ['accept_chats' => true], + ], 'secret_chats' => ['accept_chats' => true], 'serialization' => ['serialization_interval' => 30, 'cleanup_before_serialization' => false], 'upload' => ['allow_automatic_upload' => true, 'part_size' => 512 * 1024, 'parallel_chunks' => 20], 'download' => ['report_broken_media' => true, 'part_size' => 1024 * 1024, 'parallel_chunks' => 20], 'pwr' => [ 'pwr' => false, @@ -1819,12 +1818,12 @@ class MTProto extends AsyncConstruct implements TLCallback */ public function __debugInfo(): array { - $vars = get_object_vars($this); - unset($vars['full_chats']); - unset($vars['chats']); - unset($vars['referenceDatabase']); - unset($vars['minDatabase']); - unset($vars['TL']); + $vars = \get_object_vars($this); + unset($vars['full_chats'], $vars['chats'], $vars['referenceDatabase'], $vars['minDatabase'], $vars['TL']); + + + + return $vars; } const ALL_MIMES = ['webp' => [0 => 'image/webp'], 'png' => [0 => 'image/png', 1 => 'image/x-png'], 'bmp' => [0 => 'image/bmp', 1 => 'image/x-bmp', 2 => 'image/x-bitmap', 3 => 'image/x-xbitmap', 4 => 'image/x-win-bitmap', 5 => 'image/x-windows-bmp', 6 => 'image/ms-bmp', 7 => 'image/x-ms-bmp', 8 => 'application/bmp', 9 => 'application/x-bmp', 10 => 'application/x-win-bitmap'], 'gif' => [0 => 'image/gif'], 'jpeg' => [0 => 'image/jpeg', 1 => 'image/pjpeg'], 'xspf' => [0 => 'application/xspf+xml'], 'vlc' => [0 => 'application/videolan'], 'wmv' => [0 => 'video/x-ms-wmv', 1 => 'video/x-ms-asf'], 'au' => [0 => 'audio/x-au'], 'ac3' => [0 => 'audio/ac3'], 'flac' => [0 => 'audio/x-flac'], 'ogg' => [0 => 'audio/ogg', 1 => 'video/ogg', 2 => 'application/ogg'], 'kmz' => [0 => 'application/vnd.google-earth.kmz'], 'kml' => [0 => 'application/vnd.google-earth.kml+xml'], 'rtx' => [0 => 'text/richtext'], 'rtf' => [0 => 'text/rtf'], 'jar' => [0 => 'application/java-archive', 1 => 'application/x-java-application', 2 => 'application/x-jar'], 'zip' => [0 => 'application/x-zip', 1 => 'application/zip', 2 => 'application/x-zip-compressed', 3 => 'application/s-compressed', 4 => 'multipart/x-zip'], '7zip' => [0 => 'application/x-compressed'], 'xml' => [0 => 'application/xml', 1 => 'text/xml'], 'svg' => [0 => 'image/svg+xml'], '3g2' => [0 => 'video/3gpp2'], '3gp' => [0 => 'video/3gp', 1 => 'video/3gpp'], 'mp4' => [0 => 'video/mp4'], 'm4a' => [0 => 'audio/x-m4a'], 'f4v' => [0 => 'video/x-f4v'], 'flv' => [0 => 'video/x-flv'], 'webm' => [0 => 'video/webm'], 'aac' => [0 => 'audio/x-acc'], 'm4u' => [0 => 'application/vnd.mpegurl'], 'pdf' => [0 => 'application/pdf', 1 => 'application/octet-stream'], 'pptx' => [0 => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'], 'ppt' => [0 => 'application/powerpoint', 1 => 'application/vnd.ms-powerpoint', 2 => 'application/vnd.ms-office', 3 => 'application/msword'], 'docx' => [0 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'], 'xlsx' => [0 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 1 => 'application/vnd.ms-excel'], 'xl' => [0 => 'application/excel'], 'xls' => [0 => 'application/msexcel', 1 => 'application/x-msexcel', 2 => 'application/x-ms-excel', 3 => 'application/x-excel', 4 => 'application/x-dos_ms_excel', 5 => 'application/xls', 6 => 'application/x-xls'], 'xsl' => [0 => 'text/xsl'], 'mpeg' => [0 => 'video/mpeg'], 'mov' => [0 => 'video/quicktime'], 'avi' => [0 => 'video/x-msvideo', 1 => 'video/msvideo', 2 => 'video/avi', 3 => 'application/x-troff-msvideo'], 'movie' => [0 => 'video/x-sgi-movie'], 'log' => [0 => 'text/x-log'], 'txt' => [0 => 'text/plain'], 'css' => [0 => 'text/css'], 'html' => [0 => 'text/html'], 'wav' => [0 => 'audio/x-wav', 1 => 'audio/wave', 2 => 'audio/wav'], 'xhtml' => [0 => 'application/xhtml+xml'], 'tar' => [0 => 'application/x-tar'], 'tgz' => [0 => 'application/x-gzip-compressed'], 'psd' => [0 => 'application/x-photoshop', 1 => 'image/vnd.adobe.photoshop'], 'exe' => [0 => 'application/x-msdownload'], 'js' => [0 => 'application/x-javascript'], 'mp3' => [0 => 'audio/mpeg', 1 => 'audio/mpg', 2 => 'audio/mpeg3', 3 => 'audio/mp3'], 'rar' => [0 => 'application/x-rar', 1 => 'application/rar', 2 => 'application/x-rar-compressed'], 'gzip' => [0 => 'application/x-gzip'], 'hqx' => [0 => 'application/mac-binhex40', 1 => 'application/mac-binhex', 2 => 'application/x-binhex40', 3 => 'application/x-mac-binhex40'], 'cpt' => [0 => 'application/mac-compactpro'], 'bin' => [0 => 'application/macbinary', 1 => 'application/mac-binary', 2 => 'application/x-binary', 3 => 'application/x-macbinary'], 'oda' => [0 => 'application/oda'], 'ai' => [0 => 'application/postscript'], 'smil' => [0 => 'application/smil'], 'mif' => [0 => 'application/vnd.mif'], 'wbxml' => [0 => 'application/wbxml'], 'wmlc' => [0 => 'application/wmlc'], 'dcr' => [0 => 'application/x-director'], 'dvi' => [0 => 'application/x-dvi'], 'gtar' => [0 => 'application/x-gtar'], 'php' => [0 => 'application/x-httpd-php', 1 => 'application/php', 2 => 'application/x-php', 3 => 'text/php', 4 => 'text/x-php', 5 => 'application/x-httpd-php-source'], 'swf' => [0 => 'application/x-shockwave-flash'], 'sit' => [0 => 'application/x-stuffit'], 'z' => [0 => 'application/x-compress'], 'mid' => [0 => 'audio/midi'], 'aif' => [0 => 'audio/x-aiff', 1 => 'audio/aiff'], 'ram' => [0 => 'audio/x-pn-realaudio'], 'rpm' => [0 => 'audio/x-pn-realaudio-plugin'], 'ra' => [0 => 'audio/x-realaudio'], 'rv' => [0 => 'video/vnd.rn-realvideo'], 'jp2' => [0 => 'image/jp2', 1 => 'video/mj2', 2 => 'image/jpx', 3 => 'image/jpm'], 'tiff' => [0 => 'image/tiff'], 'eml' => [0 => 'message/rfc822'], 'pem' => [0 => 'application/x-x509-user-cert', 1 => 'application/x-pem-file'], 'p10' => [0 => 'application/x-pkcs10', 1 => 'application/pkcs10'], 'p12' => [0 => 'application/x-pkcs12'], 'p7a' => [0 => 'application/x-pkcs7-signature'], 'p7c' => [0 => 'application/pkcs7-mime', 1 => 'application/x-pkcs7-mime'], 'p7r' => [0 => 'application/x-pkcs7-certreqresp'], 'p7s' => [0 => 'application/pkcs7-signature'], 'crt' => [0 => 'application/x-x509-ca-cert', 1 => 'application/pkix-cert'], 'crl' => [0 => 'application/pkix-crl', 1 => 'application/pkcs-crl'], 'pgp' => [0 => 'application/pgp'], 'gpg' => [0 => 'application/gpg-keys'], 'rsa' => [0 => 'application/x-pkcs7'], 'ics' => [0 => 'text/calendar'], 'zsh' => [0 => 'text/x-scriptzsh'], 'cdr' => [0 => 'application/cdr', 1 => 'application/coreldraw', 2 => 'application/x-cdr', 3 => 'application/x-coreldraw', 4 => 'image/cdr', 5 => 'image/x-cdr', 6 => 'zz-application/zz-winassoc-cdr'], 'wma' => [0 => 'audio/x-ms-wma'], 'vcf' => [0 => 'text/x-vcard'], 'srt' => [0 => 'text/srt'], 'vtt' => [0 => 'text/vtt'], 'ico' => [0 => 'image/x-icon', 1 => 'image/x-ico', 2 => 'image/vnd.microsoft.icon'], 'csv' => [0 => 'text/x-comma-separated-values', 1 => 'text/comma-separated-values', 2 => 'application/vnd.msexcel'], 'json' => [0 => 'application/json', 1 => 'text/json']]; diff --git a/src/danog/MadelineProto/Wrappers/Templates.php b/src/danog/MadelineProto/Wrappers/Templates.php index 75959dcf..5405bcae 100644 --- a/src/danog/MadelineProto/Wrappers/Templates.php +++ b/src/danog/MadelineProto/Wrappers/Templates.php @@ -24,10 +24,10 @@ use function Amp\ByteStream\getOutputBufferStream; trait Templates { /** - * Echo page to console + * Echo page to console. * * @param string $message Error message - * + * * @return \Generator */ private function webEcho(string $message = ''): \Generator @@ -57,17 +57,17 @@ trait Templates } } /** - * Web template + * Web template. * * @var string */ private $web_template = 'MadelineProto

MadelineProto

%s

%s

'; /** - * Format message according to template + * Format message according to template. * * @param string $message Message * @param string $form Form contents - * + * * @return string */ private function webEchoTemplate(string $message, string $form): string diff --git a/tests/danog/MadelineProto/DataCenterTest.php b/tests/danog/MadelineProto/DataCenterTest.php index 17925738..535c8c44 100644 --- a/tests/danog/MadelineProto/DataCenterTest.php +++ b/tests/danog/MadelineProto/DataCenterTest.php @@ -73,7 +73,7 @@ final class DataCenterTest extends TestCase ); $API->datacenter = $datacenter; - $API->getLogger()->logger("Testing protocol $protocol using transport $transport, ".($obfuscated ? 'obfuscated ' : 'not obfuscated ').($test_mode ? 'test DC ' : 'main DC ').($ipv6 ? 'IPv6 ' : 'IPv4 ').($doh ? "DNS over HTTPS" : "DNS"); + $API->getLogger()->logger("Testing protocol $protocol using transport $transport, ".($obfuscated ? 'obfuscated ' : 'not obfuscated ').($test_mode ? 'test DC ' : 'main DC ').($ipv6 ? 'IPv6 ' : 'IPv4 ').($doh ? "DNS over HTTPS" : "DNS")); \sleep(1); try {