Update even more typehints

This commit is contained in:
Daniil Gentili 2020-10-03 15:04:35 +02:00
parent 6076118320
commit 4f69701cfc
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
23 changed files with 261 additions and 147 deletions

View File

@ -28,27 +28,27 @@ use phpDocumentor\Reflection\DocBlockFactory;
class AnnotationsBuilder class AnnotationsBuilder
{ {
/** /**
* Reflection classes * Reflection classes.
*/ */
private array $reflectionClasses = []; private array $reflectionClasses = [];
/** /**
* Logger * Logger.
*/ */
private Logger $logger; private Logger $logger;
/** /**
* Namespace * Namespace.
*/ */
private string $namespace; private string $namespace;
/** /**
* TL instance * TL instance.
*/ */
private TL $TL; private TL $TL;
/** /**
* Settings * Settings.
*/ */
private array $settings; private array $settings;
/** /**
* Output file * Output file.
*/ */
private string $output; private string $output;
public function __construct(Logger $logger, array $settings, string $output, array $reflectionClasses, string $namespace) public function __construct(Logger $logger, array $settings, string $output, array $reflectionClasses, string $namespace)
@ -309,7 +309,15 @@ class AnnotationsBuilder
if (!$type) { if (!$type) {
Logger::log("{$name} has no return type!", Logger::FATAL_ERROR); Logger::log("{$name} has no return type!", Logger::FATAL_ERROR);
} }
$internalDoc['InternalDoc'][$name]['method'] = $method->getDocComment() ?? ''; $promise = '\\'.Promise::class;
$phpdoc = $method->getDocComment() ?? '';
$phpdoc = \str_replace("@return \\Generator", "@return $promise", $phpdoc);
$phpdoc = \preg_replace(
"/@psalm-return \\\\Generator<(?:[^,]+), (?:[^,]+), (?:[^,]+), (.+)>/",
"@psalm-return $promise<$1>",
$phpdoc
);
$internalDoc['InternalDoc'][$name]['method'] = $phpdoc;
$internalDoc['InternalDoc'][$name]['method'] .= "\n ".\implode("\n ", \explode("\n", $doc)); $internalDoc['InternalDoc'][$name]['method'] .= "\n ".\implode("\n ", \explode("\n", $doc));
} }
\fwrite($handle, "<?php\n"); \fwrite($handle, "<?php\n");

View File

@ -604,7 +604,7 @@ class DataCenter
/** /**
* Get all DataCenterConnection instances. * Get all DataCenterConnection instances.
* *
* @return array<string, DataCenterConnection> * @return array<int|string, DataCenterConnection>
*/ */
public function getDataCenterConnections(): array public function getDataCenterConnections(): array
{ {

View File

@ -6,7 +6,7 @@ use Amp\Loop;
use danog\MadelineProto\Logger; use danog\MadelineProto\Logger;
/** /**
* Array caching trait * Array caching trait.
* *
* @property string $table * @property string $table
*/ */

View File

@ -5,14 +5,70 @@ namespace danog\MadelineProto\Db;
use Amp\Producer; use Amp\Producer;
use Amp\Promise; use Amp\Promise;
/**
* DB array interface.
*
* @template T as mixed
*/
interface DbArray extends DbType, \ArrayAccess, \Countable interface DbArray extends DbType, \ArrayAccess, \Countable
{ {
/**
* Get Array copy.
*
* @psalm-return Promise<array{0: string|int, 1: T}> $value
*
* @return Promise
*/
public function getArrayCopy(): Promise; public function getArrayCopy(): Promise;
/**
* Check if element is set.
*
* @param string|int $key
*
* @psalm-return Promise<bool>
*
* @return Promise
*/
public function isset($key): Promise; public function isset($key): Promise;
/**
* Get element.
*
* @param string|int $offset
*
* @psalm-return Promise<T>
*
* @return Promise
*/
public function offsetGet($offset): Promise; public function offsetGet($offset): Promise;
/**
* Set element.
*
* @param string|int $offset
* @param mixed $value
*
* @psalm-param T $value
*
* @return void
*/
public function offsetSet($offset, $value); public function offsetSet($offset, $value);
/**
* Unset element.
*
* @param string|int $offset Offset
* @return Promise
*/
public function offsetUnset($offset): Promise; public function offsetUnset($offset): Promise;
/**
* Count number of elements.
*
* @return Promise<integer>
*/
public function count(): Promise; public function count(): Promise;
/**
* Get iterator.
*
* @return Producer<array{0: string|int, 1: T}>
*/
public function getIterator(): Producer; public function getIterator(): Producer;
/** /**

View File

@ -7,7 +7,7 @@ use danog\MadelineProto\SettingsAbstract;
use ReflectionClass; use ReflectionClass;
/** /**
* Array caching trait * Array caching trait.
* *
* @property string $table * @property string $table
*/ */

View File

@ -155,11 +155,11 @@ class DocsBuilder
* Get formatted template string. * Get formatted template string.
* *
* @param string $name Template name * @param string $name Template name
* @param string[] ...$params Params * @param string ...$params Params
* *
* @return string * @return string
*/ */
protected function template(string $name, ...$params): string protected function template(string $name, string ...$params): string
{ {
return \sprintf($this->templates[$name], ...$params); return \sprintf($this->templates[$name], ...$params);
} }

View File

@ -4450,7 +4450,7 @@ class InternalDoc extends APIFactory
* *
* @param array $data Data * @param array $data Data
* *
* @return \Generator<array> * @return \Amp\Promise<array>
*/ */
public function MTProtoToBotAPI(array $data, array $extra = []) public function MTProtoToBotAPI(array $data, array $extra = [])
{ {
@ -4461,7 +4461,7 @@ class InternalDoc extends APIFactory
* *
* @param mixed $params Params * @param mixed $params Params
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function MTProtoToTd(&$params, array $extra = []) public function MTProtoToTd(&$params, array $extra = [])
{ {
@ -4472,7 +4472,7 @@ class InternalDoc extends APIFactory
* *
* @param mixed $params Params * @param mixed $params Params
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function MTProtoToTdcli($params, array $extra = []) public function MTProtoToTdcli($params, array $extra = [])
{ {
@ -4483,7 +4483,7 @@ class InternalDoc extends APIFactory
* *
* @param array $call Call * @param array $call Call
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function acceptCall(array $call, array $extra = []) public function acceptCall(array $call, array $extra = [])
{ {
@ -4494,7 +4494,7 @@ class InternalDoc extends APIFactory
* *
* @param array $params Secret chat ID * @param array $params Secret chat ID
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function acceptSecretChat($params, array $extra = []) public function acceptSecretChat($params, array $extra = [])
{ {
@ -4503,7 +4503,7 @@ class InternalDoc extends APIFactory
/** /**
* Accept terms of service update. * Accept terms of service update.
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function acceptTos(array $extra = []) public function acceptTos(array $extra = [])
{ {
@ -4514,7 +4514,7 @@ class InternalDoc extends APIFactory
* *
* @param array $user User info * @param array $user User info
* *
* @return \Generator * @return \Amp\Promise
* @throws \danog\MadelineProto\Exception * @throws \danog\MadelineProto\Exception
*/ */
public function addUser(array $user, array $extra = []) public function addUser(array $user, array $extra = [])
@ -4596,7 +4596,7 @@ class InternalDoc extends APIFactory
* *
* @param array $arguments Arguments * @param array $arguments Arguments
* *
* @return \Generator<array> * @return \Amp\Promise<array>
*/ */
public function botAPIToMTProto(array $arguments, array $extra = []) public function botAPIToMTProto(array $arguments, array $extra = [])
{ {
@ -4607,7 +4607,7 @@ class InternalDoc extends APIFactory
* *
* @param string $token Bot token * @param string $token Bot token
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function botLogin(string $token, array $extra = []) public function botLogin(string $token, array $extra = [])
{ {
@ -4618,7 +4618,11 @@ class InternalDoc extends APIFactory
* *
* @param \Generator|Promise|mixed $promise * @param \Generator|Promise|mixed $promise
* *
* @template TReturn
* @psalm-param \Generator<mixed, mixed, mixed, TReturn>|Promise<TReturn>|TReturn $promise
*
* @return Promise * @return Promise
* @psalm-return Promise<TReturn>
*/ */
public function call($promise) public function call($promise)
{ {
@ -4673,7 +4677,7 @@ class InternalDoc extends APIFactory
/** /**
* Check for terms of service update. * Check for terms of service update.
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function checkTos(array $extra = []) public function checkTos(array $extra = [])
{ {
@ -4704,7 +4708,7 @@ class InternalDoc extends APIFactory
* *
* @param string $password Password * @param string $password Password
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function complete2faLogin(string $password, array $extra = []) public function complete2faLogin(string $password, array $extra = [])
{ {
@ -4715,7 +4719,7 @@ class InternalDoc extends APIFactory
* *
* @param array $params Params * @param array $params Params
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function completeCall(array $params, array $extra = []) public function completeCall(array $params, array $extra = [])
{ {
@ -4726,7 +4730,7 @@ class InternalDoc extends APIFactory
* *
* @param string $code Login code * @param string $code Login code
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function completePhoneLogin($code, array $extra = []) public function completePhoneLogin($code, array $extra = [])
{ {
@ -4738,7 +4742,7 @@ class InternalDoc extends APIFactory
* @param string $first_name First name * @param string $first_name First name
* @param string $last_name Last name * @param string $last_name Last name
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function completeSignup(string $first_name, string $last_name = '', array $extra = []) public function completeSignup(string $first_name, string $last_name = '', array $extra = [])
{ {
@ -4749,7 +4753,7 @@ class InternalDoc extends APIFactory
* *
* @param array $params Params * @param array $params Params
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function confirmCall(array $params, array $extra = []) public function confirmCall(array $params, array $extra = [])
{ {
@ -4760,7 +4764,7 @@ class InternalDoc extends APIFactory
* *
* @param boolean $reconnectAll Whether to reconnect to all DCs * @param boolean $reconnectAll Whether to reconnect to all DCs
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function connectToAllDcs(bool $reconnectAll = true, array $extra = []) public function connectToAllDcs(bool $reconnectAll = true, array $extra = [])
{ {
@ -4771,7 +4775,7 @@ class InternalDoc extends APIFactory
* *
* THIS WILL DELETE YOUR ACCOUNT! * THIS WILL DELETE YOUR ACCOUNT!
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function declineTos(array $extra = []) public function declineTos(array $extra = [])
{ {
@ -4785,7 +4789,7 @@ class InternalDoc extends APIFactory
* @param array $rating Rating * @param array $rating Rating
* @param boolean $need_debug Need debug? * @param boolean $need_debug Need debug?
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function discardCall(array $call, array $reason, array $rating = [ public function discardCall(array $call, array $reason, array $rating = [
], bool $need_debug = true, array $extra = []) ], bool $need_debug = true, array $extra = [])
@ -4797,7 +4801,7 @@ class InternalDoc extends APIFactory
* *
* @param int $chat Secret chat ID * @param int $chat Secret chat ID
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function discardSecretChat(int $chat, array $extra = []) public function discardSecretChat(int $chat, array $extra = [])
{ {
@ -4811,7 +4815,7 @@ class InternalDoc extends APIFactory
* @param array|string $messageMedia File to download * @param array|string $messageMedia File to download
* @param callable $cb Status callback (can also use FileCallback) * @param callable $cb Status callback (can also use FileCallback)
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function downloadToBrowser($messageMedia, ?callable $cb = null, array $extra = []) public function downloadToBrowser($messageMedia, ?callable $cb = null, array $extra = [])
{ {
@ -4831,9 +4835,9 @@ class InternalDoc extends APIFactory
* @param int $end Offset where to stop downloading (inclusive) * @param int $end Offset where to stop downloading (inclusive)
* @param int $part_size Size of each chunk * @param int $part_size Size of each chunk
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|array, mixed, true> * @psalm-return \Amp\Promise<true>
*/ */
public function downloadToCallable($messageMedia, callable $callable, $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, ?int $part_size = null, array $extra = []) public function downloadToCallable($messageMedia, callable $callable, $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, ?int $part_size = null, array $extra = [])
{ {
@ -4846,9 +4850,9 @@ class InternalDoc extends APIFactory
* @param string|FileCallbackInterface $dir Directory where to download the file * @param string|FileCallbackInterface $dir Directory where to download the file
* @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface)
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<callable|null>|\Amp\Promise<mixed>|array|bool|mixed, mixed, false|string> * @psalm-return \Amp\Promise<false|string>
*/ */
public function downloadToDir($messageMedia, $dir, $cb = null, array $extra = []) public function downloadToDir($messageMedia, $dir, $cb = null, array $extra = [])
{ {
@ -4861,9 +4865,9 @@ class InternalDoc extends APIFactory
* @param string|FileCallbackInterface $file Downloaded file path * @param string|FileCallbackInterface $file Downloaded file path
* @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface)
* *
* @return \Generator Downloaded file path * @return \Amp\Promise Downloaded file path
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<callable|null>|\Amp\Promise<mixed>|array|bool|mixed, mixed, false|string> * @psalm-return \Amp\Promise<false|string>
*/ */
public function downloadToFile($messageMedia, $file, $cb = null, array $extra = []) public function downloadToFile($messageMedia, $file, $cb = null, array $extra = [])
{ {
@ -4878,9 +4882,9 @@ class InternalDoc extends APIFactory
* @param ServerRequest $request Request * @param ServerRequest $request Request
* @param callable $cb Status callback (can also use FileCallback) * @param callable $cb Status callback (can also use FileCallback)
* *
* @return \Generator Returned response * @return \Amp\Promise Returned response
* *
* @psalm-return \Generator<mixed, array, mixed, \Amp\Http\Server\Response> * @psalm-return \Amp\Promise<\Amp\Http\Server\Response>
*/ */
public function downloadToResponse($messageMedia, \Amp\Http\Server\Request $request, ?callable $cb = null, array $extra = []) public function downloadToResponse($messageMedia, \Amp\Http\Server\Request $request, ?callable $cb = null, array $extra = [])
{ {
@ -4895,9 +4899,9 @@ class InternalDoc extends APIFactory
* @param int $offset Offset where to start downloading * @param int $offset Offset where to start downloading
* @param int $end Offset where to end download * @param int $end Offset where to end download
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int, \Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<mixed>|mixed, mixed, mixed> * @psalm-return \Amp\Promise<mixed>
*/ */
public function downloadToStream($messageMedia, $stream, $cb = null, int $offset = 0, int $end = -1, array $extra = []) public function downloadToStream($messageMedia, $stream, $cb = null, int $offset = 0, int $end = -1, array $extra = [])
{ {
@ -4928,9 +4932,9 @@ class InternalDoc extends APIFactory
/** /**
* Export authorization. * Export authorization.
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<mixed, array|bool, mixed, array{0: int|string, 1: string}> * @psalm-return \Amp\Promise<array{0: int|string, 1: string}>
*/ */
public function exportAuthorization(array $extra = []) public function exportAuthorization(array $extra = [])
{ {
@ -4952,9 +4956,9 @@ class InternalDoc extends APIFactory
* *
* @param string $url URL * @param string $url URL
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int, Promise<string>, mixed, string> * @psalm-return \Amp\Promise<string>
*/ */
public function fileGetContents(string $url, array $extra = []) public function fileGetContents(string $url, array $extra = [])
{ {
@ -5003,7 +5007,7 @@ class InternalDoc extends APIFactory
* *
* @param mixed $id Chat ID * @param mixed $id Chat ID
* *
* @return \Generator<integer> * @return \Amp\Promise<integer>
*/ */
public function fullChatLastUpdated($id, array $extra = []) public function fullChatLastUpdated($id, array $extra = [])
{ {
@ -5012,7 +5016,7 @@ class InternalDoc extends APIFactory
/** /**
* Get info about the logged-in user, not cached. * Get info about the logged-in user, not cached.
* *
* @return \Generator<array|bool> * @return \Amp\Promise<array|bool>
*/ */
public function fullGetSelf(array $extra = []) public function fullGetSelf(array $extra = [])
{ {
@ -5072,7 +5076,7 @@ class InternalDoc extends APIFactory
* *
* @param string $datacenter DC ID * @param string $datacenter DC ID
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function getCdnConfig(string $datacenter, array $extra = []) public function getCdnConfig(string $datacenter, array $extra = [])
{ {
@ -5084,7 +5088,7 @@ class InternalDoc extends APIFactory
* @param array $config Current config * @param array $config Current config
* @param array $options Options for method call * @param array $options Options for method call
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function getConfig(array $config = [ public function getConfig(array $config = [
], array $options = [ ], array $options = [
@ -5124,9 +5128,9 @@ class InternalDoc extends APIFactory
* *
* @param boolean $force Whether to refetch all dialogs ignoring cache * @param boolean $force Whether to refetch all dialogs ignoring cache
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int, \Amp\Promise<bool>, mixed, list<mixed>> * @psalm-return \Amp\Promise<list<mixed>>
*/ */
public function getDialogs(bool $force = true, array $extra = []) public function getDialogs(bool $force = true, array $extra = [])
{ {
@ -5143,7 +5147,7 @@ class InternalDoc extends APIFactory
* *
* @param mixed $messageMedia File ID * @param mixed $messageMedia File ID
* *
* @return \Generator<array> * @return \Amp\Promise<array>
*/ */
public function getDownloadInfo($messageMedia, array $extra = []) public function getDownloadInfo($messageMedia, array $extra = [])
{ {
@ -5186,7 +5190,7 @@ class InternalDoc extends APIFactory
* *
* @param mixed $constructor File ID * @param mixed $constructor File ID
* *
* @return \Generator<array> * @return \Amp\Promise<array>
*/ */
public function getFileInfo($constructor, array $extra = []) public function getFileInfo($constructor, array $extra = [])
{ {
@ -5208,7 +5212,7 @@ class InternalDoc extends APIFactory
* *
* @param boolean $force Whether to refetch all dialogs ignoring cache * @param boolean $force Whether to refetch all dialogs ignoring cache
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function getFullDialogs(bool $force = true, array $extra = []) public function getFullDialogs(bool $force = true, array $extra = [])
{ {
@ -5221,9 +5225,9 @@ class InternalDoc extends APIFactory
* *
* @see https://docs.madelineproto.xyz/FullInfo.html * @see https://docs.madelineproto.xyz/FullInfo.html
* *
* @return \Generator FullInfo object * @return \Amp\Promise FullInfo object
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|array, mixed, array> * @psalm-return \Amp\Promise<array>
*/ */
public function getFullInfo($id, array $extra = []) public function getFullInfo($id, array $extra = [])
{ {
@ -5238,6 +5242,15 @@ class InternalDoc extends APIFactory
{ {
return $this->API->getHTTPClient(); return $this->API->getHTTPClient();
} }
/**
* Get current password hint.
*
* @return string
*/
public function getHint(): string
{
return $this->API->getHint();
}
/** /**
* Get bot API ID from peer object. * Get bot API ID from peer object.
* *
@ -5257,9 +5270,9 @@ class InternalDoc extends APIFactory
* *
* @see https://docs.madelineproto.xyz/Info.html * @see https://docs.madelineproto.xyz/Info.html
* *
* @return \Generator Info object * @return \Amp\Promise Info object
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<string>|array, mixed, array|mixed> * @psalm-return \Amp\Promise<array|mixed>
*/ */
public function getInfo($id, $recursive = true, array $extra = []) public function getInfo($id, $recursive = true, array $extra = [])
{ {
@ -5335,7 +5348,7 @@ class InternalDoc extends APIFactory
* *
* @param mixed $messageMedia File ID * @param mixed $messageMedia File ID
* *
* @return \Generator<array> * @return \Amp\Promise<array>
*/ */
public function getPropicInfo($data, array $extra = []) public function getPropicInfo($data, array $extra = [])
{ {
@ -5355,7 +5368,7 @@ class InternalDoc extends APIFactory
* *
* @see https://docs.madelineproto.xyz/Chat.html * @see https://docs.madelineproto.xyz/Chat.html
* *
* @return \Generator<array> Chat object * @return \Amp\Promise<array> Chat object
*/ */
public function getPwrChat($id, bool $fullfetch = true, bool $send = true, array $extra = []) public function getPwrChat($id, bool $fullfetch = true, bool $send = true, array $extra = [])
{ {
@ -5486,7 +5499,7 @@ class InternalDoc extends APIFactory
* *
* @param mixed $authorization Authorization info * @param mixed $authorization Authorization info
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function importAuthorization($authorization, array $extra = []) public function importAuthorization($authorization, array $extra = [])
{ {
@ -5508,7 +5521,7 @@ class InternalDoc extends APIFactory
* *
* @param MTProto $MadelineProto * @param MTProto $MadelineProto
* @param boolean $reset * @param boolean $reset
* @return \Generator * @return \Amp\Promise
*/ */
public function initDb(\danog\MadelineProto\MTProto $MadelineProto, bool $reset = false, array $extra = []) public function initDb(\danog\MadelineProto\MTProto $MadelineProto, bool $reset = false, array $extra = [])
{ {
@ -5579,7 +5592,7 @@ class InternalDoc extends APIFactory
/** /**
* Log out currently logged in user. * Log out currently logged in user.
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function logout(array $extra = []) public function logout(array $extra = [])
{ {
@ -5590,7 +5603,7 @@ class InternalDoc extends APIFactory
* *
* @param callable|null $callback Async callable to run * @param callable|null $callback Async callable to run
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function loop($callback = null, array $extra = []) public function loop($callback = null, array $extra = [])
{ {
@ -5661,7 +5674,7 @@ class InternalDoc extends APIFactory
* @param array $args Arguments * @param array $args Arguments
* @param array $aargs Additional arguments * @param array $aargs Additional arguments
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function methodCall(string $method, $args = [ public function methodCall(string $method, $args = [
], array $aargs = [ ], array $aargs = [
@ -5677,7 +5690,7 @@ class InternalDoc extends APIFactory
* @param array $args Arguments * @param array $args Arguments
* @param array $aargs Additional arguments * @param array $aargs Additional arguments
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function methodCallWrite(string $method, $args = [ public function methodCallWrite(string $method, $args = [
], array $aargs = [ ], array $aargs = [
@ -5746,9 +5759,9 @@ class InternalDoc extends APIFactory
* *
* @param mixed $id Peer * @param mixed $id Peer
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|array, mixed, bool> * @psalm-return \Amp\Promise<bool>
*/ */
public function peerIsset($id, array $extra = []) public function peerIsset($id, array $extra = [])
{ {
@ -5760,7 +5773,7 @@ class InternalDoc extends APIFactory
* @param string $number Phone number * @param string $number Phone number
* @param integer $sms_type SMS type * @param integer $sms_type SMS type
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function phoneLogin($number, $sms_type = 5, array $extra = []) public function phoneLogin($number, $sms_type = 5, array $extra = [])
{ {
@ -5817,7 +5830,7 @@ class InternalDoc extends APIFactory
* *
* @param int $chat Secret chat to rekey * @param int $chat Secret chat to rekey
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function rekey(int $chat, array $extra = []) public function rekey(int $chat, array $extra = [])
{ {
@ -5829,7 +5842,7 @@ class InternalDoc extends APIFactory
* @param string $message Error to report * @param string $message Error to report
* @param string $parseMode Parse mode * @param string $parseMode Parse mode
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function report(string $message, string $parseMode = '', array $extra = []) public function report(string $message, string $parseMode = '', array $extra = [])
{ {
@ -5840,7 +5853,7 @@ class InternalDoc extends APIFactory
* *
* @param mixed $user User * @param mixed $user User
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function requestCall($user, array $extra = []) public function requestCall($user, array $extra = [])
{ {
@ -5851,7 +5864,7 @@ class InternalDoc extends APIFactory
* *
* @param mixed $user User to start secret chat with * @param mixed $user User to start secret chat with
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function requestSecretChat($user, array $extra = []) public function requestSecretChat($user, array $extra = [])
{ {
@ -5871,7 +5884,7 @@ class InternalDoc extends APIFactory
* *
* @param string $username Username * @param string $username Username
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function resolveUsername(string $username, array $extra = []) public function resolveUsername(string $username, array $extra = [])
{ {
@ -5960,7 +5973,7 @@ class InternalDoc extends APIFactory
* *
* @param class-string<EventHandler> $eventHandler Event handler * @param class-string<EventHandler> $eventHandler Event handler
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function setEventHandler(string $eventHandler, array $extra = []) public function setEventHandler(string $eventHandler, array $extra = [])
{ {
@ -5980,7 +5993,7 @@ class InternalDoc extends APIFactory
* *
* @param int|string $userOrId Username(s) or peer ID(s) * @param int|string $userOrId Username(s) or peer ID(s)
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function setReportPeers($userOrId, array $extra = []) public function setReportPeers($userOrId, array $extra = [])
{ {
@ -6068,7 +6081,7 @@ class InternalDoc extends APIFactory
/** /**
* Log in to telegram (via CLI or web). * Log in to telegram (via CLI or web).
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function start(array $extra = []) public function start(array $extra = [])
{ {
@ -6088,7 +6101,7 @@ class InternalDoc extends APIFactory
* *
* @param array $params Parameters * @param array $params Parameters
* *
* @return \Generator<array> * @return \Amp\Promise<array>
*/ */
public function tdToMTProto(array $params, array $extra = []) public function tdToMTProto(array $params, array $extra = [])
{ {
@ -6136,15 +6149,20 @@ class InternalDoc extends APIFactory
* *
* If the timeout expires before the promise is resolved, a default value is returned * If the timeout expires before the promise is resolved, a default value is returned
* *
* @template TReturnAlt
* @template TReturn * @template TReturn
* @template TGenerator as \Generator<mixed, mixed, mixed, TReturn>
* *
* @param Promise<TReturn>|\Generator $promise Promise to which the timeout is applied. * @param Promise<TReturn>|\Generator $promise Promise to which the timeout is applied.
* @param int $timeout Timeout in milliseconds. * @param int $timeout Timeout in milliseconds.
* @param TReturn $default * @param mixed $default
* *
* @return Promise<TReturn> * @psalm-param Promise<TReturn>|TGenerator $promise Promise to which the timeout is applied.
* @psalm-param TReturnAlt $timeout
* *
* @throws \TypeError If $promise is not an instance of \Amp\Promise or \React\Promise\PromiseInterface. * @return Promise<TReturn|TReturnAlt>
*
* @throws \TypeError If $promise is not an instance of \Amp\Promise, \Generator or \React\Promise\PromiseInterface.
*/ */
public function timeoutWithDefault($promise, int $timeout, $default = null) public function timeoutWithDefault($promise, int $timeout, $default = null)
{ {
@ -6267,7 +6285,7 @@ class InternalDoc extends APIFactory
* *
* @param array $params The params * @param array $params The params
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function update2fa(array $params, array $extra = []) public function update2fa(array $params, array $extra = [])
{ {
@ -6278,7 +6296,7 @@ class InternalDoc extends APIFactory
* *
* @param SettingsAbstract $settings Settings * @param SettingsAbstract $settings Settings
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function updateSettings(\danog\MadelineProto\SettingsAbstract $settings, array $extra = []) public function updateSettings(\danog\MadelineProto\SettingsAbstract $settings, array $extra = [])
{ {
@ -6292,9 +6310,9 @@ class InternalDoc extends APIFactory
* @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface)
* @param boolean $encrypted Whether to encrypt file for secret chats * @param boolean $encrypted Whether to encrypt file for secret chats
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<int>|\Amp\Promise<mixed>|\Amp\Promise<null|string>|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed> * @psalm-return \Amp\Promise<mixed>
*/ */
public function upload($file, string $fileName = '', $cb = null, bool $encrypted = false, array $extra = []) public function upload($file, string $fileName = '', $cb = null, bool $encrypted = false, array $extra = [])
{ {
@ -6307,9 +6325,9 @@ class InternalDoc extends APIFactory
* @param string $fileName File name * @param string $fileName File name
* @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface)
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<int>|\Amp\Promise<mixed>|\Amp\Promise<null|string>|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed> * @psalm-return \Amp\Promise<mixed>
*/ */
public function uploadEncrypted($file, string $fileName = '', $cb = null, array $extra = []) public function uploadEncrypted($file, string $fileName = '', $cb = null, array $extra = [])
{ {
@ -6329,9 +6347,9 @@ class InternalDoc extends APIFactory
* @param boolean $seekable Whether chunks can be fetched out of order * @param boolean $seekable Whether chunks can be fetched out of order
* @param boolean $encrypted Whether to encrypt file for secret chats * @param boolean $encrypted Whether to encrypt file for secret chats
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int, \Amp\Promise|\Amp\Promise<array>, mixed, array{_: string, id: string, parts: int, name: string, mime_type: string, key_fingerprint?: mixed, key?: mixed, iv?: mixed, md5_checksum: string}> * @psalm-return \Amp\Promise<array{_: string, id: string, parts: int, name: string, mime_type: string, key_fingerprint?: mixed, key?: mixed, iv?: mixed, md5_checksum: string}>
*/ */
public function uploadFromCallable(callable $callable, int $size, string $mime, string $fileName = '', $cb = null, bool $seekable = true, bool $encrypted = false, array $extra = []) public function uploadFromCallable(callable $callable, int $size, string $mime, string $fileName = '', $cb = null, bool $seekable = true, bool $encrypted = false, array $extra = [])
{ {
@ -6347,9 +6365,9 @@ class InternalDoc extends APIFactory
* @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface)
* @param boolean $encrypted Whether to encrypt file for secret chats * @param boolean $encrypted Whether to encrypt file for secret chats
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<int>|\Amp\Promise<null|string>|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed> * @psalm-return \Amp\Promise<mixed>
*/ */
public function uploadFromStream($stream, int $size, string $mime, string $fileName = '', $cb = null, bool $encrypted = false, array $extra = []) public function uploadFromStream($stream, int $size, string $mime, string $fileName = '', $cb = null, bool $encrypted = false, array $extra = [])
{ {
@ -6362,9 +6380,9 @@ class InternalDoc extends APIFactory
* @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface)
* @param boolean $encrypted Whether to encrypt file for secret chats * @param boolean $encrypted Whether to encrypt file for secret chats
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|array, mixed, mixed> * @psalm-return \Amp\Promise<mixed>
*/ */
public function uploadFromTgfile($media, $cb = null, bool $encrypted = false, array $extra = []) public function uploadFromTgfile($media, $cb = null, bool $encrypted = false, array $extra = [])
{ {
@ -6379,9 +6397,9 @@ class InternalDoc extends APIFactory
* @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface)
* @param boolean $encrypted Whether to encrypt file for secret chats * @param boolean $encrypted Whether to encrypt file for secret chats
* *
* @return \Generator * @return \Amp\Promise
* *
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<\Amp\Http\Client\Response>|\Amp\Promise<int>|\Amp\Promise<null|string>|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed> * @psalm-return \Amp\Promise<mixed>
*/ */
public function uploadFromUrl($url, int $size = 0, string $fileName = '', $cb = null, bool $encrypted = false, array $extra = []) public function uploadFromUrl($url, int $size = 0, string $fileName = '', $cb = null, bool $encrypted = false, array $extra = [])
{ {

View File

@ -263,7 +263,8 @@ class MTProto extends AsyncConstruct implements TLCallback
/** /**
* Whether we're authorized. * Whether we're authorized.
* *
* @var integer * @var int
* @psalm-var self::NOT_LOGGED_IN|self::WAITING_*|self::LOGGED_IN
*/ */
public $authorized = self::NOT_LOGGED_IN; public $authorized = self::NOT_LOGGED_IN;
/** /**
@ -387,6 +388,10 @@ class MTProto extends AsyncConstruct implements TLCallback
* RPC reporting loop. * RPC reporting loop.
*/ */
private ?PeriodicLoopInternal $rpcLoop = null; private ?PeriodicLoopInternal $rpcLoop = null;
/**
* SEQ update loop.
*/
private ?SeqLoop $seqUpdater = null;
/** /**
* IPC server. * IPC server.
*/ */
@ -1678,6 +1683,18 @@ class MTProto extends AsyncConstruct implements TLCallback
{ {
return $this->authorized; return $this->authorized;
} }
/**
* Get current password hint.
*
* @return string
*/
public function getHint(): string
{
if ($this->authorized !== self::WAITING_PASSWORD) {
throw new Exception("Not waiting for the password!");
}
return $this->authorization['hint'];
}
/** /**
* IDs of peers where to report errors. * IDs of peers where to report errors.
* *

View File

@ -26,6 +26,8 @@ use danog\MadelineProto\MTProto;
/** /**
* Manages responses. * Manages responses.
*
* @extend Session
*/ */
trait ResponseHandler trait ResponseHandler
{ {
@ -357,7 +359,7 @@ trait ResponseHandler
$socket->setPermAuthKey(null); $socket->setPermAuthKey(null);
$socket->resetSession(); $socket->resetSession();
} }
if (in_array($response['error_message'],['USER_DEACTIVATED', 'USER_DEACTIVATED_BAN'], true)) { if (\in_array($response['error_message'], ['USER_DEACTIVATED', 'USER_DEACTIVATED_BAN'], true)) {
$this->logger->logger('!!!!!!! WARNING !!!!!!!', \danog\MadelineProto\Logger::FATAL_ERROR); $this->logger->logger('!!!!!!! WARNING !!!!!!!', \danog\MadelineProto\Logger::FATAL_ERROR);
$this->logger->logger("Telegram's flood prevention system suspended this account.", \danog\MadelineProto\Logger::ERROR); $this->logger->logger("Telegram's flood prevention system suspended this account.", \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('To continue, manual verification is required.', \danog\MadelineProto\Logger::FATAL_ERROR); $this->logger->logger('To continue, manual verification is required.', \danog\MadelineProto\Logger::FATAL_ERROR);

View File

@ -33,6 +33,7 @@ use danog\MadelineProto\Tools;
/** /**
* Manages updates. * Manages updates.
* *
* @extend MTProto
* @property Settings $settings Settings * @property Settings $settings Settings
*/ */
trait UpdateHandler trait UpdateHandler

View File

@ -115,7 +115,7 @@ class UdpBufferedStream extends DefaultStream implements BufferedStreamInterface
/** /**
* Destructor function. * Destructor function.
*/ */
public function __destruct(): void public function __destruct()
{ {
\fclose($this->buffer); \fclose($this->buffer);
} }

View File

@ -36,6 +36,12 @@ use danog\MadelineProto\Stream\RawStreamInterface;
class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface
{ {
use RawStream; use RawStream;
/**
* Stream.
*
* @var RawStreamInterface
*/
protected $stream;
private $extra; private $extra;
/** /**
* Connect to stream. * Connect to stream.

View File

@ -37,6 +37,12 @@ class SocksProxy implements RawProxyStreamInterface, BufferedProxyStreamInterfac
{ {
const REPS = [0 => 'succeeded', 1 => 'general SOCKS server failure', 2 => 'connection not allowed by ruleset', 3 => 'Network unreachable', 4 => 'Host unreachable', 5 => 'Connection refused', 6 => 'TTL expired', 7 => 'Command not supported', 8 => 'Address type not supported']; const REPS = [0 => 'succeeded', 1 => 'general SOCKS server failure', 2 => 'connection not allowed by ruleset', 3 => 'Network unreachable', 4 => 'Host unreachable', 5 => 'Connection refused', 6 => 'TTL expired', 7 => 'Command not supported', 8 => 'Address type not supported'];
use RawStream; use RawStream;
/**
* Stream.
*
* @var RawStreamInterface
*/
protected $stream;
private $extra; private $extra;
/** /**
* Connect to stream. * Connect to stream.

View File

@ -20,6 +20,7 @@
namespace danog\MadelineProto\TON; namespace danog\MadelineProto\TON;
use danog\MadelineProto\Magic; use danog\MadelineProto\Magic;
use danog\MadelineProto\Settings\Logger;
/** /**
* TON API. * TON API.
@ -29,9 +30,9 @@ class API extends InternalDoc
/** /**
* Construct API. * Construct API.
* *
* @param array $settings Settings * @param Logger $settings Settings
*/ */
public function __construct(array $settings) public function __construct(Logger $settings)
{ {
Magic::classExists(); Magic::classExists();
$this->API = new Lite($settings); $this->API = new Lite($settings);

View File

@ -987,7 +987,7 @@ class InternalDoc extends APIFactory
* *
* @param array $parameters Parameters * @param array $parameters Parameters
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function botAPItoMTProto(array $parameters, array $extra = []) public function botAPItoMTProto(array $parameters, array $extra = [])
{ {
@ -998,7 +998,11 @@ class InternalDoc extends APIFactory
* *
* @param \Generator|Promise|mixed $promise * @param \Generator|Promise|mixed $promise
* *
* @template TReturn
* @psalm-param \Generator<mixed, mixed, mixed, TReturn>|Promise<TReturn>|TReturn $promise
*
* @return Promise * @return Promise
* @psalm-return Promise<TReturn>
*/ */
public function call($promise) public function call($promise)
{ {
@ -1035,7 +1039,7 @@ class InternalDoc extends APIFactory
* *
* @param string $config Path to config file * @param string $config Path to config file
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function connect(string $config, array $extra = []) public function connect(string $config, array $extra = [])
{ {
@ -1189,7 +1193,7 @@ class InternalDoc extends APIFactory
* *
* @param callable $func Function * @param callable $func Function
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function loop(callable $func, array $extra = []) public function loop(callable $func, array $extra = [])
{ {
@ -1212,7 +1216,7 @@ class InternalDoc extends APIFactory
* @param string $methodName Method name * @param string $methodName Method name
* @param array $args Arguments * @param array $args Arguments
* *
* @return \Generator * @return \Amp\Promise
*/ */
public function methodCall(string $methodName, array $args = [ public function methodCall(string $methodName, array $args = [
], array $aargs = [ ], array $aargs = [
@ -1416,15 +1420,20 @@ class InternalDoc extends APIFactory
* *
* If the timeout expires before the promise is resolved, a default value is returned * If the timeout expires before the promise is resolved, a default value is returned
* *
* @template TReturnAlt
* @template TReturn * @template TReturn
* @template TGenerator as \Generator<mixed, mixed, mixed, TReturn>
* *
* @param Promise<TReturn>|\Generator $promise Promise to which the timeout is applied. * @param Promise<TReturn>|\Generator $promise Promise to which the timeout is applied.
* @param int $timeout Timeout in milliseconds. * @param int $timeout Timeout in milliseconds.
* @param TReturn $default * @param mixed $default
* *
* @return Promise<TReturn> * @psalm-param Promise<TReturn>|TGenerator $promise Promise to which the timeout is applied.
* @psalm-param TReturnAlt $timeout
* *
* @throws \TypeError If $promise is not an instance of \Amp\Promise or \React\Promise\PromiseInterface. * @return Promise<TReturn|TReturnAlt>
*
* @throws \TypeError If $promise is not an instance of \Amp\Promise, \Generator or \React\Promise\PromiseInterface.
*/ */
public function timeoutWithDefault($promise, int $timeout, $default = null) public function timeoutWithDefault($promise, int $timeout, $default = null)
{ {

View File

@ -20,6 +20,8 @@
namespace danog\MadelineProto\TON; namespace danog\MadelineProto\TON;
use danog\MadelineProto\Logger; use danog\MadelineProto\Logger;
use danog\MadelineProto\Settings\Logger as SettingsLogger;
use danog\MadelineProto\Settings\TLSchema;
use danog\MadelineProto\TL\TL; use danog\MadelineProto\TL\TL;
use danog\MadelineProto\Tools; use danog\MadelineProto\Tools;
use function Amp\File\get; use function Amp\File\get;
@ -38,9 +40,9 @@ class Lite
/** /**
* Misc settings. * Misc settings.
* *
* @var array * @var SettingsLogger
*/ */
private $settings = []; private SettingsLogger $settings;
/** /**
* TL serializer instance. * TL serializer instance.
* *
@ -62,14 +64,17 @@ class Lite
/** /**
* Construct settings. * Construct settings.
* *
* @param array $settings * @param SettingsLogger $settings
*/ */
public function __construct(array $settings) public function __construct(SettingsLogger $settings)
{ {
$this->settings = $settings; $this->settings = $settings;
$this->logger = Logger::getLoggerFromSettings($this->settings); $this->logger = Logger::constructorFromSettings($this->settings);
$schema = new TLSchema;
$schema->setOther(['lite_api' => __DIR__.'/../../../../schemas/TON/lite_api.tl', 'ton_api' => __DIR__.'/../../../../schemas/TON/ton_api.tl']);
/** @psalm-suppress InvalidArgument */
$this->TL = new TL($this); $this->TL = new TL($this);
$this->TL->init(['lite_api' => __DIR__.'/../../../../schemas/TON/lite_api.tl', 'ton_api' => __DIR__.'/../../../../schemas/TON/ton_api.tl']); $this->TL->init($schema);
} }
/** /**
* Connect to the lite endpoints specified in the config file. * Connect to the lite endpoints specified in the config file.

View File

@ -420,7 +420,7 @@ abstract class Tools extends StrTools
* *
* @template TReturnAlt * @template TReturnAlt
* @template TReturn * @template TReturn
* @template TGenerator as Generator<mixed, mixed, mixed, TReturn> * @template TGenerator as \Generator<mixed, mixed, mixed, TReturn>
* *
* @param Promise<TReturn>|\Generator $promise Promise to which the timeout is applied. * @param Promise<TReturn>|\Generator $promise Promise to which the timeout is applied.
* @param int $timeout Timeout in milliseconds. * @param int $timeout Timeout in milliseconds.
@ -458,10 +458,9 @@ abstract class Tools extends StrTools
/** /**
* Convert generator, promise or any other value to a promise. * Convert generator, promise or any other value to a promise.
* *
* @template TReturn
*
* @param \Generator|Promise|mixed $promise * @param \Generator|Promise|mixed $promise
* *
* @template TReturn
* @psalm-param \Generator<mixed, mixed, mixed, TReturn>|Promise<TReturn>|TReturn $promise * @psalm-param \Generator<mixed, mixed, mixed, TReturn>|Promise<TReturn>|TReturn $promise
* *
* @return Promise * @return Promise
@ -517,7 +516,7 @@ abstract class Tools extends StrTools
*/ */
public static function callForkDefer($promise): void public static function callForkDefer($promise): void
{ {
Loop::defer([self::class, 'callFork'], $promise); Loop::defer(fn () => self::callFork($promise));
} }
/** /**
* Rethrow error catched in strand. * Rethrow error catched in strand.
@ -616,7 +615,7 @@ abstract class Tools extends StrTools
* *
* @internal Generator function * @internal Generator function
* *
* @return \Generator * @return \Generator<mixed, mixed, mixed, ?callable>
*/ */
public static function flockGenerator(string $file, int $operation, float $polling, ?Promise $token = null, $failureCb = null): \Generator public static function flockGenerator(string $file, int $operation, float $polling, ?Promise $token = null, $failureCb = null): \Generator
{ {

View File

@ -49,19 +49,6 @@ trait Events
* @var array<string, callable> * @var array<string, callable>
*/ */
private $eventHandlerMethods = []; private $eventHandlerMethods = [];
/**
* Initialize existing event handler.
*
* @internal
*
* @return void
*/
public function initExistingEventHandler(): void
{
if ($this->event_handler && \class_exists($this->event_handler) && \is_subclass_of($this->API->event_handler, EventHandler::class)) {
$this->initEventHandler($this->API->event_handler);
}
}
/** /**
* Initialize event handler. * Initialize event handler.
* *

View File

@ -45,10 +45,11 @@ trait Start
} }
if ($this->getWebTemplate() === 'legacy') { if ($this->getWebTemplate() === 'legacy') {
if ($this instanceof Client) { if ($this instanceof Client) {
$this->setWebTemplate(yield from $this->getSettings()); $settings = yield from $this->getSettings();
} else { } else {
$this->setWebTemplate($this->settings); $settings = $this->settings;
} }
$this->setWebTemplate($settings->getTemplates()->getHtmlTemplate());
} }
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
if (\strpos(yield Tools::readLine(Lang::$current_lang['loginChoosePrompt']), 'b') !== false) { if (\strpos(yield Tools::readLine(Lang::$current_lang['loginChoosePrompt']), 'b') !== false) {

View File

@ -20,6 +20,7 @@
namespace danog\MadelineProto\Wrappers; namespace danog\MadelineProto\Wrappers;
use \danog\MadelineProto\MTProto; use \danog\MadelineProto\MTProto;
use danog\MadelineProto\Ipc\Client;
use danog\MadelineProto\Lang; use danog\MadelineProto\Lang;
use function Amp\ByteStream\getOutputBufferStream; use function Amp\ByteStream\getOutputBufferStream;
@ -59,7 +60,10 @@ trait Templates
$form = "<input type='text' name='phone_code' placeholder='$phone' required/>"; $form = "<input type='text' name='phone_code' placeholder='$phone' required/>";
} elseif ($auth === MTProto::WAITING_PASSWORD) { } elseif ($auth === MTProto::WAITING_PASSWORD) {
$title = Lang::$current_lang['loginUserPassWeb']; $title = Lang::$current_lang['loginUserPassWeb'];
$hint = \htmlentities(\sprintf(Lang::$current_lang['loginUserPassHint'], $this->authorization['hint'])); $hint = \htmlentities(\sprintf(
Lang::$current_lang['loginUserPassHint'],
$this instanceof Client ? yield from $this->getHint() : $this->getHint()
));
$form = "<input type='password' name='password' placeholder='$hint' required/>"; $form = "<input type='password' name='password' placeholder='$hint' required/>";
} elseif ($auth === MTProto::WAITING_SIGNUP) { } elseif ($auth === MTProto::WAITING_SIGNUP) {
$title = Lang::$current_lang['signupWeb']; $title = Lang::$current_lang['signupWeb'];

View File

@ -1,17 +1,11 @@
<?php <?php
use danog\MadelineProto\Logger; use danog\MadelineProto\Settings\Logger as SettingsLogger;
use danog\MadelineProto\TON\API; use danog\MadelineProto\TON\API;
require 'vendor/autoload.php'; require 'vendor/autoload.php';
$API = new API( $API = new API(new SettingsLogger);
[
'logger' => [
'logger' => Logger::ECHO_LOGGER
]
]
);
$API->async(true); $API->async(true);
$API->loop( $API->loop(