From 699f0660e00967523521493d28fe71b292450ab3 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 11 Jul 2020 20:13:06 +0200 Subject: [PATCH] Finalize IPC --- .../MadelineProto/AbstractAPIFactory.php | 29 +++++++++++-------- src/danog/MadelineProto/FastAPI.php | 1 + 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/danog/MadelineProto/AbstractAPIFactory.php b/src/danog/MadelineProto/AbstractAPIFactory.php index 66df9683..c52540d8 100644 --- a/src/danog/MadelineProto/AbstractAPIFactory.php +++ b/src/danog/MadelineProto/AbstractAPIFactory.php @@ -177,24 +177,29 @@ abstract class AbstractAPIFactory extends AsyncConstruct /** * Get fully resolved method list for object, including snake_case and camelCase variants. * - * @param API $value Value + * @param API $value Value + * @param string $class Custom class name * * @return array */ - protected static function getInternalMethodList($value): array + protected static function getInternalMethodList($value, string $class = null): array + { + return \array_map(fn ($method) => [$value, $method], self::getInternalMethodListClass($class ?? \get_class($value))); + } + /** + * Get fully resolved method list for object, including snake_case and camelCase variants. + * + * @param string $class Class name + * + * @return array + */ + protected static function getInternalMethodListClass(string $class): array { static $cache = []; - $class = \get_class($value); if (isset($cache[$class])) { - return \array_map( - static function ($v) use ($value) { - return [$value, $v]; - }, - $cache[$class] - ); + return $cache[$class]; } - - $methods = \get_class_methods($value); + $methods = \get_class_methods($class); foreach ($methods as $method) { if ($method == 'methodCallAsyncRead') { unset($methods[\array_search('methodCall', $methods)]); @@ -227,6 +232,6 @@ abstract class AbstractAPIFactory extends AsyncConstruct } $cache[$class] = $finalMethods; - return self::getInternalMethodList($value); + return $finalMethods; } } diff --git a/src/danog/MadelineProto/FastAPI.php b/src/danog/MadelineProto/FastAPI.php index 2d3ac095..7ea8cae9 100644 --- a/src/danog/MadelineProto/FastAPI.php +++ b/src/danog/MadelineProto/FastAPI.php @@ -84,6 +84,7 @@ class FastAPI extends API } $this->API = new Client($session->getIpcPath(), $this->logger); yield from $this->API->initAsynchronously(); + $this->methods = self::getInternalMethodList($this->API, MTProto::class); $this->logger->logger(Lang::$current_lang['madelineproto_ready'], Logger::NOTICE); } /**