Multiple fixes

This commit is contained in:
Daniil Gentili 2019-06-13 14:43:30 +02:00
parent 1a2a6db17f
commit 2d70f51b2c
4 changed files with 28 additions and 4 deletions

View File

@ -10,7 +10,7 @@
}, },
"require": { "require": {
"php": ">=7.1.0", "php": ">=7.1.0",
"danog/primemodule": "^1.0.3", "danog/primemodule": "^1",
"danog/magicalserializer": "^1.0", "danog/magicalserializer": "^1.0",
"phpseclib/phpseclib": "dev-master#27370df as 2.0.15", "phpseclib/phpseclib": "dev-master#27370df as 2.0.15",
"vlucas/phpdotenv": "^3", "vlucas/phpdotenv": "^3",

View File

@ -32,6 +32,7 @@ class API extends APIFactory
public $getting_api_id = false; public $getting_api_id = false;
public $my_telegram_org_wrapper; public $my_telegram_org_wrapper;
public $asyncAPIPromise; public $asyncAPIPromise;
private $oldInstance = false;
public function __magic_construct($params = [], $settings = []) public function __magic_construct($params = [], $settings = [])
{ {
@ -137,7 +138,7 @@ class API extends APIFactory
if (isset($unserialized->API)) { if (isset($unserialized->API)) {
$this->API = $unserialized->API; $this->API = $unserialized->API;
$this->APIFactory(); $this->APIFactory();
$unserialized->donotlog = true; $unserialized->oldInstance = true;
$deferred->resolve(); $deferred->resolve();
yield $this->API->initAsync(); yield $this->API->initAsync();
$this->APIFactory(); $this->APIFactory();
@ -152,6 +153,15 @@ class API extends APIFactory
} }
$params = $settings; $params = $settings;
} }
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;
}
\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);
}
if (!isset($params['app_info']['api_id']) || !$params['app_info']['api_id']) { if (!isset($params['app_info']['api_id']) || !$params['app_info']['api_id']) {
$app = yield $this->api_start_async($params); $app = yield $this->api_start_async($params);
$params['app_info']['api_id'] = $app['api_id']; $params['app_info']['api_id'] = $app['api_id'];
@ -194,7 +204,7 @@ class API extends APIFactory
if ($this->asyncInitPromise) { if ($this->asyncInitPromise) {
$this->init(); $this->init();
} }
if (!isset($this->donotlog)) { if (!$this->oldInstance) {
if ($this->API) { if ($this->API) {
$this->API->logger('Shutting down MadelineProto (normally or due to an exception, idk)'); $this->API->logger('Shutting down MadelineProto (normally or due to an exception, idk)');
$this->API->destructing = true; $this->API->destructing = true;

View File

@ -254,6 +254,11 @@ class MTProto extends AsyncConstruct implements TLCallback
return $this->datacenter->getHTTPClient(); return $this->datacenter->getHTTPClient();
} }
public function getDNSClient()
{
return $this->datacenter->getDNSClient();
}
public function fileGetContents($url): \Generator public function fileGetContents($url): \Generator
{ {
return $this->datacenter->fileGetContents($url); return $this->datacenter->fileGetContents($url);

View File

@ -157,7 +157,16 @@ class Magic
] ]
); );
resolver(new Rfc8484StubResolver($DohConfig)); resolver(new Rfc8484StubResolver($DohConfig));
if (php_sapi_name() !== 'cli') {
try {
error_reporting(E_ALL);
ini_set('log_errors', 1);
ini_set('error_log', Magic::$script_cwd.'/MadelineProto.log');
error_log('Enabled PHP logging');
} catch (\danog\MadelineProto\Exception $e) {
//$this->logger->logger('Could not enable PHP logging');
}
}
self::$inited = true; self::$inited = true;
} }
} }