From 3b4d45bd3443398ab2f418926ef33d288cd471b6 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 8 Jun 2019 13:29:54 +0200 Subject: [PATCH] Workaround for async init --- docs | 2 +- src/danog/MadelineProto/API.php | 18 ++++++++++++++++-- src/danog/MadelineProto/APIFactory.php | 4 ++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs b/docs index dc05dc5c..d06f79a1 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit dc05dc5cebfcec90ac7851928c522a4d635dbab6 +Subproject commit d06f79a1848bd380d6ad9a71a3ead0c2c2ded4a1 diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 73796bf2..185bd9c0 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -43,14 +43,28 @@ class API extends APIFactory $this->asyncAPIPromise = null; }); $this->setInitPromise($this->__construct_async($params, $settings, $deferred)); + foreach (get_object_vars(new APIFactory('', $this, $this->async)) as $key => $var) { + if (in_array($key, ['namespace', 'API', 'lua', 'async', 'asyncAPIPromise', 'methods', 'asyncInitPromise'])) { + continue; + } + if (is_null($this->{$key})) { + $this->{$key} = new APIFactory($key, $this->API, $this->async); + } + } } public function __construct_async($params, $settings, $deferred) { if (is_string($params)) { if (!\danog\MadelineProto\Logger::$default) { - if (!isset($settings['logger']['logger_param'])) $settings['logger']['logger_param'] = Magic::$script_cwd.'/MadelineProto.log'; - if (!isset($settings['logger']['logger'])) $settings['logger']['logger'] = php_sapi_name() === 'cli' ? 3 : 2; + if (!isset($settings['logger']['logger_param'])) { + $settings['logger']['logger_param'] = Magic::$script_cwd.'/MadelineProto.log'; + } + + if (!isset($settings['logger']['logger'])) { + $settings['logger']['logger'] = php_sapi_name() === 'cli' ? 3 : 2; + } + \danog\MadelineProto\Logger::constructor($settings['logger']['logger'], $settings['logger']['logger_param'], '', isset($settings['logger']['logger_level']) ? $settings['logger']['logger_level'] : Logger::VERBOSE, isset($settings['logger']['max_size']) ? $settings['logger']['max_size'] : 100 * 1024 * 1024); } $realpaths = Serialization::realpaths($params); diff --git a/src/danog/MadelineProto/APIFactory.php b/src/danog/MadelineProto/APIFactory.php index 0a375ee5..dd800001 100644 --- a/src/danog/MadelineProto/APIFactory.php +++ b/src/danog/MadelineProto/APIFactory.php @@ -123,10 +123,10 @@ class APIFactory extends AsyncConstruct protected $methods = []; - public function __construct($namespace, $API, &$async) + public function __construct($namespace, &$API, &$async) { $this->namespace = $namespace.'.'; - $this->API = $API; + $this->API = &$API; $this->async = &$async; }