From cac9b280b04ce4b972dd3f100648bb248610cc6c Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 27 Jul 2017 09:04:46 +0200 Subject: [PATCH] Lua fixes --- src/danog/MadelineProto/APIFactory.php | 15 ++++++++++++++- src/danog/MadelineProto/Lua.php | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/danog/MadelineProto/APIFactory.php b/src/danog/MadelineProto/APIFactory.php index 92c59ada..62c8fc30 100644 --- a/src/danog/MadelineProto/APIFactory.php +++ b/src/danog/MadelineProto/APIFactory.php @@ -135,7 +135,20 @@ class APIFactory return method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && $this->is_array($arguments[0])) ? $arguments[0] : [], $aargs); } try { - return method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && $this->is_array($arguments[0])) ? $arguments[0] : [], $aargs); + $deserialized = method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && $this->is_array($arguments[0])) ? $arguments[0] : [], $aargs); + array_walk_recursive($deserialized, function (&$value, $key) { + if (is_object($value)) { + $newval = []; + foreach (get_class_methods($value) as $key => $name) { + $newval[$key] = [$value, $name]; + } + foreach ($value as $key => $name) { + $newval[$key] = $name; + } + $value = $newval; + } + }); + return $deserialized; } catch (\danog\MadelineProto\Exception $e) { return ['error_code' => $e->getCode(), 'error' => $e->getMessage()]; } catch (\danog\MadelineProto\RPCErrorException $e) { diff --git a/src/danog/MadelineProto/Lua.php b/src/danog/MadelineProto/Lua.php index db30ec5d..f76334dd 100644 --- a/src/danog/MadelineProto/Lua.php +++ b/src/danog/MadelineProto/Lua.php @@ -58,6 +58,11 @@ class Lua } $this->{$namespace} = $methods[$namespace]; } + $this->MadelineProto->lua = true; + foreach ($this->MadelineProto->get_methods_namespaced() as $method => $namespace) { + $this->MadelineProto->{$namespace}->lua = true; + } + } public function tdcli_function($params, $cb = null, $cb_extra = null) @@ -133,6 +138,18 @@ class Lua public function __call($name, $params) { + array_walk_recursive($params, function (&$value, $key) { + if (is_object($value)) { + $newval = []; + foreach (get_class_methods($value) as $key => $name) { + $newval[$key] = [$value, $name]; + } + foreach ($value as $key => $name) { + $newval[$key] = $name; + } + $value = $newval; + } + }); try { return $this->Lua->{$name}(...$params); } catch (\danog\MadelineProto\RPCErrorException $e) {