Make more methods internal
This commit is contained in:
parent
3a9dde8c3f
commit
75602e5de0
@ -20,11 +20,16 @@
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
use Amp\Deferred;
|
||||
use Amp\Promise;
|
||||
|
||||
use function Amp\File\exists;
|
||||
use function Amp\File\get;
|
||||
use function Amp\File\put;
|
||||
use function Amp\File\rename as renameAsync;
|
||||
|
||||
/**
|
||||
* Main API wrapper for MadelineProto.
|
||||
*/
|
||||
class API extends InternalDoc
|
||||
{
|
||||
use \danog\Serializable;
|
||||
@ -38,13 +43,40 @@ class API extends InternalDoc
|
||||
* @var MTProto
|
||||
*/
|
||||
public $API;
|
||||
/**
|
||||
* Whether we're getting our API ID.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $getting_api_id = false;
|
||||
/**
|
||||
* my.telegram.org API wrapper.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @var MyTelegramOrgWrapper
|
||||
*/
|
||||
public $my_telegram_org_wrapper;
|
||||
/**
|
||||
* Async ini tpromise.
|
||||
*
|
||||
* @var Promise
|
||||
*/
|
||||
public $asyncAPIPromise;
|
||||
private $oldInstance = false;
|
||||
private $destructing = false;
|
||||
|
||||
public function __magic_construct($params = [], $settings = [])
|
||||
/**
|
||||
* Magic constructor function.
|
||||
*
|
||||
* @param array $params Params
|
||||
* @param array $settings Settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __magic_construct($params = [], $settings = []): void
|
||||
{
|
||||
Magic::classExists();
|
||||
$deferred = new Deferred();
|
||||
@ -63,7 +95,16 @@ class API extends InternalDoc
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct_async($params, $settings, $deferred)
|
||||
/**
|
||||
* Async constructor function.
|
||||
*
|
||||
* @param mixed $params Params
|
||||
* @param mixed $settings Settings
|
||||
* @param mixed $deferred Deferred
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function __construct_async($params, $settings, $deferred): \Generator
|
||||
{
|
||||
if (\is_string($params)) {
|
||||
Logger::constructorFromSettings($settings);
|
||||
@ -186,7 +227,14 @@ class API extends InternalDoc
|
||||
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['madelineproto_ready'], Logger::NOTICE);
|
||||
}
|
||||
|
||||
public function async($async)
|
||||
/**
|
||||
* Enable or disable async.
|
||||
*
|
||||
* @param bool $async Whether to enable or disable async
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function async(bool $async): void
|
||||
{
|
||||
$this->async = $async;
|
||||
|
||||
@ -197,11 +245,11 @@ class API extends InternalDoc
|
||||
}
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
//$this->APIFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destruct function.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (\danog\MadelineProto\Magic::$has_thread && \is_object(\Thread::getCurrentThread()) || Magic::isFork()) {
|
||||
@ -223,18 +271,37 @@ class API extends InternalDoc
|
||||
//restore_error_handler();
|
||||
}
|
||||
|
||||
public function __sleep()
|
||||
/**
|
||||
* Sleep function.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep(): array
|
||||
{
|
||||
return ['API', 'web_api_template', 'getting_api_id', 'my_telegram_org_wrapper'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Custom fast getSelf.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
public function myGetSelf()
|
||||
{
|
||||
return isset($this->API) && isset($this->API->authorization['user']) ? $this->API->authorization['user'] : false;
|
||||
}
|
||||
|
||||
public function APIFactory()
|
||||
/**
|
||||
* Init API wrapper.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function APIFactory(): void
|
||||
{
|
||||
if ($this->API && !$this->API->asyncInitPromise) {
|
||||
foreach ($this->API->getMethodNamespaces() as $namespace) {
|
||||
@ -281,7 +348,12 @@ class API extends InternalDoc
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllMethods()
|
||||
/**
|
||||
* Get full list of MTProto and API methods.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllMethods(): array
|
||||
{
|
||||
if ($this->asyncInitPromise) {
|
||||
$this->init();
|
||||
@ -294,14 +366,20 @@ class API extends InternalDoc
|
||||
return \array_merge($methods, \get_class_methods($this->API));
|
||||
}
|
||||
|
||||
public function serialize($filename = null)
|
||||
/**
|
||||
* Serialize session.
|
||||
*
|
||||
* @param string $filename File name
|
||||
*
|
||||
* @internal Do not use this manually, the session is already serialized automatically
|
||||
*
|
||||
* @return Promise
|
||||
*/
|
||||
public function serialize(string $filename = ''): Promise
|
||||
{
|
||||
return Tools::callFork((function () use ($filename) {
|
||||
if ($filename === null) {
|
||||
$filename = $this->session;
|
||||
}
|
||||
if (empty($filename)) {
|
||||
return;
|
||||
$filename = $this->session;
|
||||
}
|
||||
//Logger::log(\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']);
|
||||
|
||||
|
@ -23,12 +23,50 @@ use danog\MadelineProto\Async\AsyncConstruct;
|
||||
|
||||
abstract class AbstractAPIFactory extends AsyncConstruct
|
||||
{
|
||||
/**
|
||||
* Namespace.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $namespace = '';
|
||||
/**
|
||||
* MTProto instance.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @var MTProto
|
||||
*/
|
||||
public $API;
|
||||
/**
|
||||
* Whether lua is being used.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $lua = false;
|
||||
/**
|
||||
* Whether async is enabled.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $async = false;
|
||||
/**
|
||||
* Async init promise.
|
||||
*
|
||||
* @var Promise
|
||||
*/
|
||||
public $asyncAPIPromise;
|
||||
|
||||
/**
|
||||
* Method list.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $methods = [];
|
||||
|
||||
public function __construct($namespace, &$API, &$async)
|
||||
@ -38,12 +76,29 @@ abstract class AbstractAPIFactory extends AsyncConstruct
|
||||
$this->async = &$async;
|
||||
}
|
||||
|
||||
public function async($async)
|
||||
/**
|
||||
* Enable or disable async.
|
||||
*
|
||||
* @param bool $async Whether to enable or disable async
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function async(bool $async): void
|
||||
{
|
||||
$this->async = $async;
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
/**
|
||||
* Call async wrapper function.
|
||||
*
|
||||
* @param string $name Method name
|
||||
* @param array $arguments Arguments
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call(string $name, array $arguments)
|
||||
{
|
||||
$yielded = Tools::call($this->__call_async($name, $arguments));
|
||||
$async = $this->lua === false && (\is_array(\end($arguments)) && isset(\end($arguments)['async']) ? \end($arguments)['async'] : ($this->async && $name !== 'loop'));
|
||||
@ -65,7 +120,17 @@ abstract class AbstractAPIFactory extends AsyncConstruct
|
||||
}
|
||||
}
|
||||
|
||||
public function __call_async($name, $arguments)
|
||||
/**
|
||||
* Call async wrapper function.
|
||||
*
|
||||
* @param string $name Method name
|
||||
* @param array $arguments Arguments
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function __call_async(string $name, array $arguments): \Generator
|
||||
{
|
||||
if ($this->asyncInitPromise) {
|
||||
yield $this->initAsynchronously();
|
||||
@ -108,7 +173,16 @@ abstract class AbstractAPIFactory extends AsyncConstruct
|
||||
return yield $this->methods[$lower_name](...$arguments);
|
||||
}
|
||||
|
||||
public function &__get($name)
|
||||
/**
|
||||
* Get attribute.
|
||||
*
|
||||
* @param string $name Attribute nam
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function &__get(string $name)
|
||||
{
|
||||
if ($this->asyncAPIPromise) {
|
||||
Tools::wait($this->asyncAPIPromise);
|
||||
@ -125,7 +199,17 @@ abstract class AbstractAPIFactory extends AsyncConstruct
|
||||
return $this->API->storage[$name];
|
||||
}
|
||||
|
||||
public function __set($name, $value)
|
||||
/**
|
||||
* Set an attribute.
|
||||
*
|
||||
* @param string $name Name
|
||||
* @param mixed $value Value
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __set(string $name, $value)
|
||||
{
|
||||
if ($this->asyncAPIPromise) {
|
||||
Tools::wait($this->asyncAPIPromise);
|
||||
@ -141,7 +225,14 @@ abstract class AbstractAPIFactory extends AsyncConstruct
|
||||
return $this->API->storage[$name] = $value;
|
||||
}
|
||||
|
||||
public function __isset($name)
|
||||
/**
|
||||
* Whether an attribute exists.
|
||||
*
|
||||
* @param string $name Attribute name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function __isset(string $name): bool
|
||||
{
|
||||
if ($this->asyncAPIPromise) {
|
||||
Tools::wait($this->asyncAPIPromise);
|
||||
@ -150,7 +241,14 @@ abstract class AbstractAPIFactory extends AsyncConstruct
|
||||
return isset($this->API->storage[$name]);
|
||||
}
|
||||
|
||||
public function __unset($name)
|
||||
/**
|
||||
* Unset attribute.
|
||||
*
|
||||
* @param string $name Attribute name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __unset(string $name): void
|
||||
{
|
||||
if ($this->asyncAPIPromise) {
|
||||
Tools::wait($this->asyncAPIPromise);
|
||||
|
@ -91,7 +91,7 @@ class AnnotationsBuilder
|
||||
|
||||
$class = new \ReflectionClass($this->reflectionClasses['API']);
|
||||
$methods = $class->getMethods(\ReflectionMethod::IS_STATIC | \ReflectionMethod::IS_PUBLIC);
|
||||
$ignoreMethods = [];
|
||||
$ignoreMethods = ['fetchserializableobject'];
|
||||
foreach ($methods as $method) {
|
||||
$ignoreMethods[$method->getName()] = $method->getName();
|
||||
}
|
||||
|
@ -29,23 +29,47 @@ use danog\MadelineProto\Tools;
|
||||
*/
|
||||
class AsyncConstruct
|
||||
{
|
||||
/**
|
||||
* Async init promise.
|
||||
*
|
||||
* @var Promise
|
||||
*/
|
||||
public $asyncInitPromise;
|
||||
|
||||
public function init()
|
||||
/**
|
||||
* Blockingly init.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
if ($this->asyncInitPromise) {
|
||||
Tools::wait($this->asyncInitPromise);
|
||||
}
|
||||
}
|
||||
|
||||
public function initAsynchronously()
|
||||
/**
|
||||
* Asynchronously init.
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function initAsynchronously(): \Generator
|
||||
{
|
||||
if ($this->asyncInitPromise) {
|
||||
yield $this->asyncInitPromise;
|
||||
}
|
||||
}
|
||||
|
||||
public function setInitPromise($promise)
|
||||
/**
|
||||
* Set init promise.
|
||||
*
|
||||
* @param Promise $promise
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setInitPromise($promise): void
|
||||
{
|
||||
$this->asyncInitPromise = Tools::callFork($promise);
|
||||
$this->asyncInitPromise->onResolve(function ($error, $result) {
|
||||
|
@ -4173,15 +4173,6 @@ class InternalDoc extends APIFactory
|
||||
{
|
||||
return $this->__call(__FUNCTION__, [$reconnectAll, $extra]);
|
||||
}
|
||||
/**
|
||||
* Clean up MadelineProto session after logout.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetSession(array $extra = []): void
|
||||
{
|
||||
$this->__call(__FUNCTION__, [$extra]);
|
||||
}
|
||||
/**
|
||||
* Reset the update state and fetch all updates from the beginning.
|
||||
*
|
||||
@ -4357,71 +4348,6 @@ class InternalDoc extends APIFactory
|
||||
{
|
||||
return $this->__call(__FUNCTION__, [$method, $args, $aargs, $extra]);
|
||||
}
|
||||
/**
|
||||
* AES KDF function for MTProto v2.
|
||||
*
|
||||
* @param string $msg_key Message key
|
||||
* @param string $auth_key Auth key
|
||||
* @param boolean $to_server To server/from server direction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function aesCalculate(string $msg_key, string $auth_key, bool $to_server = true): array
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::aesCalculate($msg_key, $auth_key, $to_server);
|
||||
}
|
||||
/**
|
||||
* AES KDF function for MTProto v1.
|
||||
*
|
||||
* @param string $msg_key Message key
|
||||
* @param string $auth_key Auth key
|
||||
* @param boolean $to_server To server/from server direction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function oldAesCalculate(string $msg_key, string $auth_key, bool $to_server = true): array
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::oldAesCalculate($msg_key, $auth_key, $to_server);
|
||||
}
|
||||
/**
|
||||
* CTR encrypt.
|
||||
*
|
||||
* @param string $message Message to encrypt
|
||||
* @param string $key Key
|
||||
* @param string $iv IV
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ctrEncrypt(string $message, string $key, string $iv): string
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::ctrEncrypt($message, $key, $iv);
|
||||
}
|
||||
/**
|
||||
* IGE encrypt.
|
||||
*
|
||||
* @param string $message Message to encrypt
|
||||
* @param string $key Key
|
||||
* @param string $iv IV
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function igeEncrypt(string $message, string $key, string $iv): string
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::igeEncrypt($message, $key, $iv);
|
||||
}
|
||||
/**
|
||||
* CTR decrypt.
|
||||
*
|
||||
* @param string $message Message to encrypt
|
||||
* @param string $key Key
|
||||
* @param string $iv IV
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function igeDecrypt(string $message, string $key, string $iv): string
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::igeDecrypt($message, $key, $iv);
|
||||
}
|
||||
/**
|
||||
* Convert MTProto channel ID to bot API channel ID.
|
||||
*
|
||||
|
@ -1497,6 +1497,8 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
/**
|
||||
* Clean up MadelineProto session after logout.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetSession(): void
|
||||
|
@ -28,6 +28,8 @@ trait Crypt
|
||||
* @param string $auth_key Auth key
|
||||
* @param boolean $to_server To server/from server direction
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function aesCalculate(string $msg_key, string $auth_key, bool $to_server = true): array
|
||||
@ -48,6 +50,8 @@ trait Crypt
|
||||
* @param string $auth_key Auth key
|
||||
* @param boolean $to_server To server/from server direction
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function oldAesCalculate(string $msg_key, string $auth_key, bool $to_server = true): array
|
||||
@ -70,6 +74,8 @@ trait Crypt
|
||||
* @param string $key Key
|
||||
* @param string $iv IV
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function ctrEncrypt(string $message, string $key, string $iv): string
|
||||
@ -88,6 +94,8 @@ trait Crypt
|
||||
* @param string $key Key
|
||||
* @param string $iv IV
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function igeEncrypt(string $message, string $key, string $iv): string
|
||||
@ -105,6 +113,8 @@ trait Crypt
|
||||
* @param string $key Key
|
||||
* @param string $iv IV
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function igeDecrypt(string $message, string $key, string $iv): string
|
||||
|
@ -86,7 +86,7 @@ class APIFactory extends AbstractAPIFactory
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call_async($name, $arguments)
|
||||
public function __call_async(string $name, array $arguments): \Generator
|
||||
{
|
||||
$lower_name = \strtolower($name);
|
||||
if ($this->namespace !== '' || !isset($this->methods[$lower_name])) {
|
||||
@ -95,8 +95,8 @@ class APIFactory extends AbstractAPIFactory
|
||||
$aargs['apifactory'] = true;
|
||||
$args = isset($arguments[0]) && \is_array($arguments[0]) ? $arguments[0] : [];
|
||||
|
||||
return $this->API->methodCall($name, $args, $aargs);
|
||||
return yield $this->API->methodCall($name, $args, $aargs);
|
||||
}
|
||||
return $this->methods[$lower_name](...$arguments);
|
||||
return yield $this->methods[$lower_name](...$arguments);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,9 @@ trait Tools
|
||||
* Sanify TL obtained from JSON for TL serialization.
|
||||
*
|
||||
* @param array $input Data to sanitize
|
||||
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function convertJsonTL(array $input): array
|
||||
|
Loading…
x
Reference in New Issue
Block a user