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": {
"php": ">=7.1.0",
"danog/primemodule": "^1.0.3",
"danog/primemodule": "^1",
"danog/magicalserializer": "^1.0",
"phpseclib/phpseclib": "dev-master#27370df as 2.0.15",
"vlucas/phpdotenv": "^3",

View File

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

View File

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

View File

@ -157,7 +157,16 @@ class Magic
]
);
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;
}
}