2016-08-07 23:23:10 +02:00
|
|
|
<?php
|
2018-02-24 17:54:13 +01:00
|
|
|
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
/**
|
|
|
|
* API module.
|
|
|
|
*
|
|
|
|
* This file is part of MadelineProto.
|
|
|
|
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU Affero General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License along with MadelineProto.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @author Daniil Gentili <daniil@daniil.it>
|
2019-05-31 12:18:10 +02:00
|
|
|
* @copyright 2016-2019 Daniil Gentili <daniil@daniil.it>
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
|
|
|
|
*
|
|
|
|
* @link https://docs.madelineproto.xyz MadelineProto documentation
|
|
|
|
*/
|
2018-02-25 17:50:03 +01:00
|
|
|
|
2016-08-07 23:23:10 +02:00
|
|
|
namespace danog\MadelineProto;
|
2016-08-08 18:10:28 +02:00
|
|
|
|
2019-05-22 17:35:16 +02:00
|
|
|
use Amp\Deferred;
|
2019-06-23 17:46:51 +02:00
|
|
|
use function Amp\File\exists;
|
2019-09-02 17:08:36 +02:00
|
|
|
use function Amp\File\get;
|
|
|
|
use function Amp\File\put;
|
|
|
|
use function Amp\File\rename as renameAsync;
|
2019-05-22 17:35:16 +02:00
|
|
|
|
2019-09-18 20:46:20 +02:00
|
|
|
class API extends InternalDoc
|
2016-08-07 23:23:30 +02:00
|
|
|
{
|
2017-05-16 15:12:04 +02:00
|
|
|
use \danog\Serializable;
|
2018-03-22 20:50:57 +01:00
|
|
|
use \danog\MadelineProto\Wrappers\ApiStart;
|
|
|
|
use \danog\MadelineProto\Wrappers\ApiTemplates;
|
2017-08-29 17:00:31 +02:00
|
|
|
public $session;
|
2017-10-09 12:49:01 +02:00
|
|
|
public $serialized = 0;
|
2019-09-14 14:21:11 +02:00
|
|
|
/**
|
2019-09-14 15:39:42 +02:00
|
|
|
* Instance of MadelineProto.
|
2019-09-14 14:21:11 +02:00
|
|
|
*
|
|
|
|
* @var MTProto
|
|
|
|
*/
|
2018-03-11 18:36:32 +01:00
|
|
|
public $API;
|
2018-03-22 20:50:57 +01:00
|
|
|
public $getting_api_id = false;
|
|
|
|
public $my_telegram_org_wrapper;
|
2019-05-22 17:35:16 +02:00
|
|
|
public $asyncAPIPromise;
|
2019-06-13 14:43:30 +02:00
|
|
|
private $oldInstance = false;
|
2019-06-13 14:58:31 +02:00
|
|
|
private $destructing = false;
|
2018-02-25 17:50:03 +01:00
|
|
|
|
2018-03-12 22:10:49 +01:00
|
|
|
public function __magic_construct($params = [], $settings = [])
|
2016-08-07 23:23:30 +02:00
|
|
|
{
|
2019-10-29 21:33:23 +01:00
|
|
|
Magic::classExists();
|
2019-06-04 14:55:58 +02:00
|
|
|
$deferred = new Deferred();
|
2019-05-22 17:35:16 +02:00
|
|
|
$this->asyncAPIPromise = $deferred->promise();
|
|
|
|
$this->asyncAPIPromise->onResolve(function () {
|
|
|
|
$this->asyncAPIPromise = null;
|
|
|
|
});
|
|
|
|
$this->setInitPromise($this->__construct_async($params, $settings, $deferred));
|
2019-09-02 17:08:36 +02:00
|
|
|
foreach (\get_object_vars(new APIFactory('', $this, $this->async)) as $key => $var) {
|
|
|
|
if (\in_array($key, ['namespace', 'API', 'lua', 'async', 'asyncAPIPromise', 'methods', 'asyncInitPromise'])) {
|
2019-06-08 13:29:54 +02:00
|
|
|
continue;
|
|
|
|
}
|
2019-09-02 17:08:36 +02:00
|
|
|
if (\is_null($this->{$key})) {
|
2019-06-08 13:29:54 +02:00
|
|
|
$this->{$key} = new APIFactory($key, $this->API, $this->async);
|
|
|
|
}
|
|
|
|
}
|
2019-05-22 17:35:16 +02:00
|
|
|
}
|
2019-06-04 14:55:58 +02:00
|
|
|
|
2019-05-22 17:35:16 +02:00
|
|
|
public function __construct_async($params, $settings, $deferred)
|
|
|
|
{
|
2019-09-02 17:08:36 +02:00
|
|
|
if (\is_string($params)) {
|
2019-06-20 20:21:31 +02:00
|
|
|
Logger::constructorFromSettings($settings);
|
2019-06-08 13:29:54 +02:00
|
|
|
|
2018-02-25 17:49:40 +01:00
|
|
|
$realpaths = Serialization::realpaths($params);
|
2018-03-14 15:29:38 +01:00
|
|
|
$this->session = $realpaths['file'];
|
|
|
|
|
2019-06-23 17:46:51 +02:00
|
|
|
if (yield exists($realpaths['file'])) {
|
|
|
|
Logger::log('Waiting for shared lock of serialization lockfile...');
|
|
|
|
$unlock = yield Tools::flock($realpaths['lockfile'], LOCK_SH);
|
|
|
|
Logger::log('Shared lock acquired, deserializing...');
|
2018-02-25 17:50:03 +01:00
|
|
|
|
2018-02-20 12:13:43 +01:00
|
|
|
try {
|
2019-06-23 17:46:51 +02:00
|
|
|
$tounserialize = yield get($realpaths['file']);
|
2018-02-20 12:13:43 +01:00
|
|
|
} finally {
|
2019-06-23 17:46:51 +02:00
|
|
|
$unlock();
|
2018-02-20 12:13:43 +01:00
|
|
|
}
|
2019-10-29 21:33:23 +01:00
|
|
|
\danog\MadelineProto\Magic::classExists();
|
2018-02-25 17:50:03 +01:00
|
|
|
|
2017-11-03 13:02:01 +01:00
|
|
|
try {
|
2019-09-02 17:08:36 +02:00
|
|
|
$unserialized = \unserialize($tounserialize);
|
2017-11-03 13:02:01 +01:00
|
|
|
} catch (\danog\MadelineProto\Bug74586Exception $e) {
|
2019-09-02 17:08:36 +02:00
|
|
|
\class_exists('\\Volatile');
|
|
|
|
$tounserialize = \str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $tounserialize);
|
2018-03-22 20:50:57 +01:00
|
|
|
foreach (['RSA', 'TL\\TLMethod', 'TL\\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\\Types\\Button', 'TL\\Types\\Bytes', 'APIFactory'] as $class) {
|
2019-09-02 17:08:36 +02:00
|
|
|
\class_exists('\\danog\\MadelineProto\\'.$class);
|
2018-03-22 20:50:57 +01:00
|
|
|
}
|
2017-11-03 13:02:01 +01:00
|
|
|
$unserialized = \danog\Serialization::unserialize($tounserialize);
|
|
|
|
} catch (\danog\MadelineProto\Exception $e) {
|
2019-05-02 21:30:50 +02:00
|
|
|
if ($e->getFile() === 'MadelineProto' && $e->getLine() === 1) {
|
|
|
|
throw $e;
|
|
|
|
}
|
2019-09-02 17:08:36 +02:00
|
|
|
if (\defined('MADELINEPROTO_TEST') && MADELINEPROTO_TEST === 'pony') {
|
2019-05-10 13:34:44 +02:00
|
|
|
throw $e;
|
|
|
|
}
|
2019-09-02 17:08:36 +02:00
|
|
|
\class_exists('\\Volatile');
|
2018-03-22 20:50:57 +01:00
|
|
|
foreach (['RSA', 'TL\\TLMethod', 'TL\\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\\Types\\Button', 'TL\\Types\\Bytes', 'APIFactory'] as $class) {
|
2019-09-02 17:08:36 +02:00
|
|
|
\class_exists('\\danog\\MadelineProto\\'.$class);
|
2018-03-22 20:50:57 +01:00
|
|
|
}
|
2019-06-12 20:51:38 +02:00
|
|
|
$changed = false;
|
2019-09-02 17:08:36 +02:00
|
|
|
if (\strpos($tounserialize, 'O:26:"danog\\MadelineProto\\Button":') !== false) {
|
|
|
|
$tounserialize = \str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $tounserialize);
|
2019-06-12 20:51:38 +02:00
|
|
|
$changed = true;
|
|
|
|
}
|
2019-09-02 17:08:36 +02:00
|
|
|
if (\strpos($e->getMessage(), "Erroneous data format for unserializing 'phpseclib\\Math\\BigInteger'") === 0) {
|
|
|
|
$tounserialize = \str_replace('phpseclib\\Math\\BigInteger', 'phpseclib\\Math\\BigIntegor', $tounserialize);
|
2019-06-12 20:51:38 +02:00
|
|
|
$changed = true;
|
2017-11-03 13:02:01 +01:00
|
|
|
}
|
2019-06-12 20:51:38 +02:00
|
|
|
|
|
|
|
Logger::log((string) $e, Logger::ERROR);
|
2019-06-13 19:46:58 +02:00
|
|
|
if (!$changed) {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
2017-11-03 13:02:01 +01:00
|
|
|
$unserialized = \danog\Serialization::unserialize($tounserialize);
|
2019-06-07 02:48:25 +02:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
Logger::log((string) $e, Logger::ERROR);
|
|
|
|
throw $e;
|
2017-11-03 13:02:01 +01:00
|
|
|
}
|
|
|
|
if ($unserialized instanceof \danog\PlaceHolder) {
|
|
|
|
$unserialized = \danog\Serialization::unserialize($tounserialize);
|
|
|
|
}
|
2018-03-12 22:10:49 +01:00
|
|
|
if ($unserialized === false) {
|
|
|
|
throw new Exception(\danog\MadelineProto\Lang::$current_lang['deserialization_error']);
|
|
|
|
}
|
2018-03-22 20:50:57 +01:00
|
|
|
$this->web_api_template = $unserialized->web_api_template;
|
|
|
|
$this->my_telegram_org_wrapper = $unserialized->my_telegram_org_wrapper;
|
|
|
|
$this->getting_api_id = $unserialized->getting_api_id;
|
|
|
|
|
2018-03-12 22:10:49 +01:00
|
|
|
if (isset($unserialized->API)) {
|
|
|
|
$this->API = $unserialized->API;
|
|
|
|
$this->APIFactory();
|
2019-06-13 14:43:30 +02:00
|
|
|
$unserialized->oldInstance = true;
|
2019-05-22 17:35:16 +02:00
|
|
|
$deferred->resolve();
|
2019-10-29 21:28:02 +01:00
|
|
|
yield $this->API->initAsynchronously();
|
2019-05-22 17:35:16 +02:00
|
|
|
$this->APIFactory();
|
2019-07-18 23:48:35 +02:00
|
|
|
//\danog\MadelineProto\Logger::log('Ping...', Logger::ULTRA_VERBOSE);
|
2019-05-22 17:35:16 +02:00
|
|
|
$this->asyncInitPromise = null;
|
2019-07-18 23:48:35 +02:00
|
|
|
//$pong = yield $this->ping(['ping_id' => 3], ['async' => true]);
|
|
|
|
//\danog\MadelineProto\Logger::log('Pong: '.$pong['ping_id'], Logger::ULTRA_VERBOSE);
|
2019-05-22 17:35:16 +02:00
|
|
|
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['madelineproto_ready'], Logger::NOTICE);
|
2018-03-22 20:50:57 +01:00
|
|
|
return;
|
2018-03-12 22:10:49 +01:00
|
|
|
}
|
2017-11-08 13:04:40 +01:00
|
|
|
}
|
2018-03-12 22:10:49 +01:00
|
|
|
$params = $settings;
|
2017-11-03 13:02:01 +01:00
|
|
|
}
|
2019-06-20 20:21:31 +02:00
|
|
|
Logger::constructorFromSettings($settings);
|
|
|
|
|
2018-03-22 20:50:57 +01:00
|
|
|
if (!isset($params['app_info']['api_id']) || !$params['app_info']['api_id']) {
|
2019-10-29 21:33:23 +01:00
|
|
|
$app = yield $this->APIStart($params);
|
2018-03-22 20:50:57 +01:00
|
|
|
$params['app_info']['api_id'] = $app['api_id'];
|
|
|
|
$params['app_info']['api_hash'] = $app['api_hash'];
|
|
|
|
}
|
2016-11-17 11:49:32 +01:00
|
|
|
$this->API = new MTProto($params);
|
2019-05-22 17:35:16 +02:00
|
|
|
$this->APIFactory();
|
|
|
|
$deferred->resolve();
|
2019-06-23 17:46:51 +02:00
|
|
|
Logger::log(\danog\MadelineProto\Lang::$current_lang['apifactory_start'], Logger::VERBOSE);
|
2019-10-29 21:28:02 +01:00
|
|
|
yield $this->API->initAsynchronously();
|
2019-05-22 17:35:16 +02:00
|
|
|
$this->APIFactory();
|
|
|
|
$this->asyncInitPromise = null;
|
2019-07-18 23:48:35 +02:00
|
|
|
//\danog\MadelineProto\Logger::log('Ping...', Logger::ULTRA_VERBOSE);
|
|
|
|
//$pong = yield $this->ping(['ping_id' => 3], ['async' => true]);
|
|
|
|
//\danog\MadelineProto\Logger::log('Pong: '.$pong['ping_id'], Logger::ULTRA_VERBOSE);
|
2019-05-22 17:35:16 +02:00
|
|
|
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['madelineproto_ready'], Logger::NOTICE);
|
Added documentation, simplified code, organized exceptions, added some more examples in testing.php, decided to unset flags in deserialized responses, moved message id arrays to Connection classes, added wrappers for logging in to telegram as a bot or as a user and for logging out, fixed deserializing of gzip packed objects, added more logging, fixed bugs, added methods to get and parse configuration, saved some fairies, fixed exporting/importing of authorization, added some wakeup methods to prevent problems during serialization, added support for ipv6 and automagical detection too. I think we can safely say this is now a beta.
2016-11-25 00:15:22 +01:00
|
|
|
}
|
2018-02-25 17:50:03 +01:00
|
|
|
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
public function async($async)
|
|
|
|
{
|
|
|
|
$this->async = $async;
|
|
|
|
|
2019-05-22 17:35:16 +02:00
|
|
|
if ($this->API) {
|
2019-09-02 17:08:36 +02:00
|
|
|
if ($this->API->event_handler && \class_exists($this->API->event_handler) && \is_subclass_of($this->API->event_handler, '\danog\MadelineProto\EventHandler')) {
|
2019-05-22 17:35:16 +02:00
|
|
|
$this->API->setEventHandler($this->API->event_handler);
|
|
|
|
}
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 13:14:21 +02:00
|
|
|
public function __wakeup()
|
|
|
|
{
|
2019-06-12 20:51:38 +02:00
|
|
|
//$this->APIFactory();
|
Added documentation, simplified code, organized exceptions, added some more examples in testing.php, decided to unset flags in deserialized responses, moved message id arrays to Connection classes, added wrappers for logging in to telegram as a bot or as a user and for logging out, fixed deserializing of gzip packed objects, added more logging, fixed bugs, added methods to get and parse configuration, saved some fairies, fixed exporting/importing of authorization, added some wakeup methods to prevent problems during serialization, added support for ipv6 and automagical detection too. I think we can safely say this is now a beta.
2016-11-25 00:15:22 +01:00
|
|
|
}
|
2018-02-25 17:50:03 +01:00
|
|
|
|
2017-04-21 13:14:21 +02:00
|
|
|
public function __destruct()
|
|
|
|
{
|
2019-10-29 21:33:23 +01:00
|
|
|
if (\danog\MadelineProto\Magic::$has_thread && \is_object(\Thread::getCurrentThread()) || Magic::isFork()) {
|
2017-05-16 15:12:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-05-22 17:35:16 +02:00
|
|
|
if ($this->asyncInitPromise) {
|
|
|
|
$this->init();
|
|
|
|
}
|
2019-06-13 14:43:30 +02:00
|
|
|
if (!$this->oldInstance) {
|
2019-06-08 21:01:57 +02:00
|
|
|
if ($this->API) {
|
|
|
|
$this->API->logger('Shutting down MadelineProto (normally or due to an exception, idk)');
|
|
|
|
$this->API->destructing = true;
|
|
|
|
} else {
|
|
|
|
Logger::log('Shutting down MadelineProto (normally or due to an exception, idk)');
|
|
|
|
}
|
|
|
|
$this->destructing = true;
|
2019-09-12 19:54:43 +02:00
|
|
|
Tools::wait($this->serialize(), true);
|
2019-06-07 18:33:06 +02:00
|
|
|
}
|
2018-04-04 15:51:10 +02:00
|
|
|
//restore_error_handler();
|
2016-08-07 23:23:10 +02:00
|
|
|
}
|
2018-02-25 17:50:03 +01:00
|
|
|
|
2017-04-21 13:14:21 +02:00
|
|
|
public function __sleep()
|
|
|
|
{
|
2018-03-22 20:50:57 +01:00
|
|
|
return ['API', 'web_api_template', 'getting_api_id', 'my_telegram_org_wrapper'];
|
2017-04-21 13:14:21 +02:00
|
|
|
}
|
2018-02-25 17:50:03 +01:00
|
|
|
|
2019-06-04 14:55:58 +02:00
|
|
|
|
2019-10-29 21:33:23 +01:00
|
|
|
public function myGetSelf()
|
2019-05-31 17:43:49 +02:00
|
|
|
{
|
2019-06-14 12:36:08 +02:00
|
|
|
return isset($this->API) && isset($this->API->authorization['user']) ? $this->API->authorization['user'] : false;
|
2019-05-31 17:43:49 +02:00
|
|
|
}
|
2019-06-04 14:55:58 +02:00
|
|
|
|
2016-12-24 17:20:45 +01:00
|
|
|
public function APIFactory()
|
|
|
|
{
|
2019-06-07 20:56:40 +02:00
|
|
|
if ($this->API && !$this->API->asyncInitPromise) {
|
2019-10-29 21:33:23 +01:00
|
|
|
foreach ($this->API->getMethodNamespaces() as $namespace) {
|
2019-05-22 17:35:16 +02:00
|
|
|
$this->{$namespace} = new APIFactory($namespace, $this->API, $this->async);
|
2018-03-22 20:50:57 +01:00
|
|
|
}
|
2019-09-02 17:08:36 +02:00
|
|
|
$methods = \get_class_methods($this->API);
|
2019-05-22 17:35:16 +02:00
|
|
|
foreach ($methods as $method) {
|
2019-10-29 22:41:31 +01:00
|
|
|
if ($method == 'methodCallAsyncRead') {
|
|
|
|
unset($methods[\array_search('methodCall', $methods)]);
|
2019-09-02 17:08:36 +02:00
|
|
|
} elseif (\stripos($method, 'async') !== false) {
|
|
|
|
if (\strpos($method, '_async') !== false) {
|
|
|
|
unset($methods[\array_search(\str_ireplace('_async', '', $method), $methods)]);
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
} else {
|
2019-09-02 17:08:36 +02:00
|
|
|
unset($methods[\array_search(\str_ireplace('async', '', $method), $methods)]);
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->methods = [];
|
|
|
|
foreach ($methods as $method) {
|
|
|
|
$actual_method = $method;
|
|
|
|
|
2019-10-29 22:41:31 +01:00
|
|
|
if ($method == 'methodCallAsyncRead') {
|
|
|
|
$method = 'methodCall';
|
2019-09-02 17:08:36 +02:00
|
|
|
} elseif (\stripos($method, 'async') !== false) {
|
|
|
|
if (\strpos($method, '_async') !== false) {
|
|
|
|
$method = \str_ireplace('_async', '', $method);
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
} else {
|
2019-09-02 17:08:36 +02:00
|
|
|
$method = \str_ireplace('async', '', $method);
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
}
|
|
|
|
}
|
2019-10-29 22:41:31 +01:00
|
|
|
$actual_method = $actual_method === 'getSelf' ? [$this, 'myGetSelf'] : [$this->API, $actual_method];
|
2019-09-02 17:08:36 +02:00
|
|
|
$this->methods[\strtolower($method)] = $actual_method;
|
|
|
|
if (\strpos($method, '_') !== false) {
|
|
|
|
$this->methods[\strtolower(\str_replace('_', '', $method))] = $actual_method;
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
} else {
|
2019-10-29 21:33:23 +01:00
|
|
|
$this->methods[\strtolower(Tools::fromCamelCase($method))] = $actual_method;
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 20:50:57 +01:00
|
|
|
$this->API->wrapper = $this;
|
2019-09-02 17:08:36 +02:00
|
|
|
if ($this->API->event_handler && \class_exists($this->API->event_handler) && \is_subclass_of($this->API->event_handler, '\danog\MadelineProto\EventHandler')) {
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
$this->API->setEventHandler($this->API->event_handler);
|
|
|
|
}
|
2016-12-24 17:20:45 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-16 13:58:52 +02:00
|
|
|
|
2019-10-29 21:33:23 +01:00
|
|
|
public function getAllMethods()
|
2018-04-16 13:56:00 +02:00
|
|
|
{
|
2019-05-22 17:35:16 +02:00
|
|
|
if ($this->asyncInitPromise) {
|
|
|
|
$this->init();
|
|
|
|
}
|
2018-04-16 13:56:00 +02:00
|
|
|
$methods = [];
|
2018-04-16 13:58:52 +02:00
|
|
|
foreach ($this->API->methods->by_id as $method) {
|
|
|
|
$methods[] = $method['method'];
|
|
|
|
}
|
|
|
|
|
2019-09-02 17:08:36 +02:00
|
|
|
return \array_merge($methods, \get_class_methods($this->API));
|
2018-04-16 13:56:00 +02:00
|
|
|
}
|
2018-02-25 17:50:03 +01:00
|
|
|
|
2019-05-22 17:35:16 +02:00
|
|
|
public function serialize($filename = null)
|
2017-02-11 15:35:10 +01:00
|
|
|
{
|
2019-09-02 17:21:20 +02:00
|
|
|
return Tools::callFork((function () use ($filename) {
|
2019-05-22 17:35:16 +02:00
|
|
|
if ($filename === null) {
|
|
|
|
$filename = $this->session;
|
|
|
|
}
|
|
|
|
if (empty($filename)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-12 19:54:43 +02:00
|
|
|
//Logger::log(\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']);
|
2018-03-23 16:39:58 +01:00
|
|
|
|
2019-05-22 17:35:16 +02:00
|
|
|
if ($filename == '') {
|
|
|
|
throw new \danog\MadelineProto\Exception('Empty filename');
|
|
|
|
}
|
2019-09-01 23:39:29 +02:00
|
|
|
if (isset($this->API->flushSettings) && $this->API->flushSettings) {
|
|
|
|
$this->API->flushSettings = false;
|
2019-05-22 17:35:16 +02:00
|
|
|
$this->API->__construct($this->API->settings);
|
|
|
|
}
|
|
|
|
if ($this->API === null && !$this->getting_api_id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($this->API && $this->API->asyncInitPromise) {
|
2019-10-29 21:28:02 +01:00
|
|
|
yield $this->API->initAsynchronously();
|
2019-05-22 17:35:16 +02:00
|
|
|
}
|
2019-09-02 17:08:36 +02:00
|
|
|
$this->serialized = \time();
|
2019-05-22 17:35:16 +02:00
|
|
|
$realpaths = Serialization::realpaths($filename);
|
2019-09-12 19:54:43 +02:00
|
|
|
//Logger::log('Waiting for exclusive lock of serialization lockfile...');
|
2019-09-02 17:08:36 +02:00
|
|
|
|
2019-06-23 17:46:51 +02:00
|
|
|
$unlock = yield Tools::flock($realpaths['lockfile'], LOCK_EX);
|
2019-09-02 17:08:36 +02:00
|
|
|
|
2019-09-12 19:54:43 +02:00
|
|
|
//Logger::log('Lock acquired, serializing');
|
2019-05-22 17:35:16 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (!$this->getting_api_id) {
|
|
|
|
$update_closure = $this->API->settings['updates']['callback'];
|
|
|
|
if ($this->API->settings['updates']['callback'] instanceof \Closure) {
|
|
|
|
$this->API->settings['updates']['callback'] = [$this->API, 'noop'];
|
|
|
|
}
|
|
|
|
$logger_closure = $this->API->settings['logger']['logger_param'];
|
|
|
|
if ($this->API->settings['logger']['logger_param'] instanceof \Closure) {
|
|
|
|
$this->API->settings['logger']['logger_param'] = [$this->API, 'noop'];
|
|
|
|
}
|
|
|
|
}
|
2019-09-02 17:08:36 +02:00
|
|
|
$wrote = yield put($realpaths['tempfile'], \serialize($this));
|
|
|
|
yield renameAsync($realpaths['tempfile'], $realpaths['file']);
|
2019-05-22 17:35:16 +02:00
|
|
|
} finally {
|
|
|
|
if (!$this->getting_api_id) {
|
|
|
|
$this->API->settings['updates']['callback'] = $update_closure;
|
|
|
|
$this->API->settings['logger']['logger_param'] = $logger_closure;
|
|
|
|
}
|
2019-06-23 17:46:51 +02:00
|
|
|
$unlock();
|
2019-05-22 17:35:16 +02:00
|
|
|
}
|
2019-09-12 19:54:43 +02:00
|
|
|
//Logger::log('Done serializing');
|
2019-05-22 17:35:16 +02:00
|
|
|
|
|
|
|
return $wrote;
|
|
|
|
})());
|
2017-02-11 15:35:10 +01:00
|
|
|
}
|
2018-02-25 17:50:03 +01:00
|
|
|
}
|