MadelineProto/src/danog/MadelineProto/TL/TL.php

1016 lines
46 KiB
PHP
Raw Normal View History

2016-06-23 23:51:08 +02:00
<?php
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
/**
* TL 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>
2020-02-17 14:13:46 +01:00
* @copyright 2016-2020 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
*
2019-10-31 15:07:35 +01:00
* @link https://docs.madelineproto.xyz MadelineProto documentation
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-02-24 17:54:39 +01:00
2016-08-08 18:10:13 +02:00
namespace danog\MadelineProto\TL;
2016-08-08 18:10:28 +02:00
use Amp\Promise;
2019-10-31 15:06:25 +01:00
use danog\MadelineProto\MTProto;
use danog\MadelineProto\MTProto\OutgoingMessage;
use danog\MadelineProto\Settings\TLSchema;
2020-04-05 22:22:47 +02:00
use danog\MadelineProto\Tools;
2019-10-31 15:06:25 +01:00
2019-10-31 15:07:35 +01:00
/**
2019-10-31 20:48:06 +01:00
* TL serialization.
2019-10-31 15:07:35 +01:00
*/
class TL
2016-07-14 15:15:50 +02:00
{
2019-10-31 15:06:25 +01:00
/**
2019-10-31 20:48:06 +01:00
* Highest available secret chat layer version.
2019-10-31 15:06:25 +01:00
*
* @var integer
*/
2019-11-01 12:45:15 +01:00
private $secretLayer = -1;
2019-10-31 15:06:25 +01:00
/**
2019-10-31 20:48:06 +01:00
* Constructors.
2019-10-31 15:06:25 +01:00
*
2019-10-31 22:41:22 +01:00
* @var TLConstructors
2019-10-31 15:06:25 +01:00
*/
2019-10-31 20:48:06 +01:00
private $constructors;
2019-10-31 15:06:25 +01:00
/**
2019-10-31 20:48:06 +01:00
* Methods.
2019-10-31 15:06:25 +01:00
*
2019-10-31 22:41:22 +01:00
* @var TLMethods
2019-10-31 15:06:25 +01:00
*/
2019-10-31 20:48:06 +01:00
private $methods;
2019-10-31 15:06:25 +01:00
/**
2019-10-31 20:48:06 +01:00
* TD Constructors.
2019-10-31 15:06:25 +01:00
*
* @var TLConstructors
*/
2019-11-01 12:45:15 +01:00
private $tdConstructors;
2019-10-31 15:06:25 +01:00
/**
2019-10-31 20:48:06 +01:00
* TD Methods.
2019-10-31 15:06:25 +01:00
*
2019-10-31 22:41:22 +01:00
* @var TLMethods
2019-10-31 15:06:25 +01:00
*/
2019-11-01 12:45:15 +01:00
private $tdMethods;
2019-10-31 15:06:25 +01:00
/**
2019-10-31 20:48:06 +01:00
* Descriptions.
2019-10-31 15:06:25 +01:00
*
* @var array
*/
2019-11-01 12:45:15 +01:00
private $tdDescriptions;
2019-10-31 15:06:25 +01:00
/**
2019-10-31 20:48:06 +01:00
* TL callbacks.
2019-10-31 15:06:25 +01:00
*
* @var array
*/
2019-11-01 12:45:15 +01:00
private $callbacks = [];
2019-10-31 15:06:25 +01:00
/**
2019-10-31 20:48:06 +01:00
* API instance.
2019-10-31 15:06:25 +01:00
*
* @var \danog\MadelineProto\MTProto
*/
private $API;
/**
2019-10-31 20:48:06 +01:00
* Constructor function.
2019-10-31 15:06:25 +01:00
*
* @param MTProto $API API instance
*/
2019-10-31 20:48:06 +01:00
public function __construct($API = null)
{
2019-10-31 15:06:25 +01:00
$this->API = $API;
}
2019-10-31 20:48:06 +01:00
/**
* Get secret chat layer version.
*
* @return integer
*/
public function getSecretLayer(): int
2016-07-14 15:15:50 +02:00
{
2019-11-01 12:45:15 +01:00
return $this->secretLayer;
2019-10-31 20:48:06 +01:00
}
/**
* Get constructors.
*
2020-10-01 21:04:53 +02:00
* @param bool $td
2019-10-31 20:48:06 +01:00
*
2019-10-31 22:41:22 +01:00
* @return TLConstructors
2019-10-31 20:48:06 +01:00
*/
2019-10-31 22:41:22 +01:00
public function getConstructors(bool $td = false): TLConstructors
2019-10-31 20:48:06 +01:00
{
2019-11-01 12:45:15 +01:00
return $td ? $this->tdConstructors : $this->constructors;
2019-10-31 20:48:06 +01:00
}
/**
* Get methods.
*
2020-10-01 21:04:53 +02:00
* @param bool $td
2019-10-31 20:48:06 +01:00
*
2019-10-31 22:41:22 +01:00
* @return TLMethods
2019-10-31 20:48:06 +01:00
*/
2019-10-31 22:41:22 +01:00
public function getMethods(bool $td = false): TLMethods
2019-10-31 20:48:06 +01:00
{
2019-11-01 12:45:15 +01:00
return $td ? $this->tdMethods : $this->methods;
2019-10-31 20:48:06 +01:00
}
/**
* Get TL descriptions.
*
* @return array
*/
2019-12-27 18:26:47 +01:00
public function &getDescriptions(): array
2019-10-31 20:48:06 +01:00
{
2019-11-01 12:45:15 +01:00
return $this->tdDescriptions;
2019-10-31 20:48:06 +01:00
}
/**
* Initialize TL parser.
*
* @param TLSchema $files Scheme files
2019-10-31 20:48:06 +01:00
* @param TLCallback[] $objects TL Callback objects
*
* @return void
*/
public function init(TLSchema $files, array $objects = [])
2019-10-31 20:48:06 +01:00
{
$this->API->logger->logger(\danog\MadelineProto\Lang::$current_lang['TL_loading'], \danog\MadelineProto\Logger::VERBOSE);
2019-10-29 21:33:23 +01:00
$this->updateCallbacks($objects);
2019-10-31 22:41:22 +01:00
$this->constructors = new TLConstructors();
$this->methods = new TLMethods();
2019-11-01 12:45:15 +01:00
$this->tdConstructors = new TLConstructors();
$this->tdMethods = new TLMethods();
$this->tdDescriptions = ['types' => [], 'constructors' => [], 'methods' => []];
2020-10-01 18:02:54 +02:00
foreach (\array_filter([
'api' => $files->getAPISchema(),
'mtproto' => $files->getMTProtoSchema(),
'secret' => $files->getSecretSchema(),
...$files->getOther()
2020-10-01 18:02:54 +02:00
]) as $scheme_type => $file) {
2019-10-31 20:48:06 +01:00
$this->API->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['file_parsing'], \basename($file)), \danog\MadelineProto\Logger::VERBOSE);
2020-04-05 22:22:47 +02:00
$filec = \file_get_contents(Tools::absolute($file));
2019-09-02 17:08:36 +02:00
$TL_dict = \json_decode($filec, true);
if ($TL_dict === null) {
$TL_dict = ['methods' => [], 'constructors' => []];
$type = 'constructors';
$layer = null;
2019-09-02 17:08:36 +02:00
$tl_file = \explode("\n", $filec);
$key = 0;
$e = null;
$class = null;
$dparams = [];
2019-12-14 16:47:04 +01:00
$lineBuf = '';
foreach ($tl_file as $line) {
2019-09-02 17:08:36 +02:00
$line = \rtrim($line);
if (\preg_match('|^//@|', $line)) {
$list = \explode(' @', \str_replace('//', ' ', $line));
foreach ($list as $elem) {
2017-03-11 19:55:56 +01:00
if ($elem === '') {
continue;
}
2019-09-02 17:08:36 +02:00
$elem = \explode(' ', $elem, 2);
if ($elem[0] === 'class') {
2019-09-02 17:08:36 +02:00
$elem = \explode(' ', $elem[1], 2);
$class = $elem[0];
continue;
}
if ($elem[0] === 'description') {
2019-09-02 17:08:36 +02:00
if (!\is_null($class)) {
2019-11-01 12:45:15 +01:00
$this->tdDescriptions['types'][$class] = $elem[1];
$class = null;
2017-03-11 19:55:56 +01:00
} else {
$e = $elem[1];
}
continue;
}
2017-03-11 19:55:56 +01:00
if ($elem[0] === 'param_description') {
$elem[0] = 'description';
}
$dparams[$elem[0]] = $elem[1];
}
continue;
}
2019-09-02 17:08:36 +02:00
$line = \preg_replace(['|//.*|', '|^\\s+$|'], '', $line);
if ($line === '') {
2017-01-02 19:52:29 +01:00
continue;
}
if ($line === '---functions---') {
2017-01-02 19:52:29 +01:00
$type = 'methods';
continue;
}
if ($line === '---types---') {
$type = 'constructors';
continue;
}
2020-01-31 19:29:43 +01:00
if (\preg_match('|^===(\\d*)===|', $line, $matches)) {
$layer = (int) $matches[1];
2017-01-02 19:52:29 +01:00
continue;
}
2019-09-02 17:08:36 +02:00
if (\strpos($line, 'vector#') === 0) {
2017-01-02 19:52:29 +01:00
continue;
}
2019-09-02 17:08:36 +02:00
if (\strpos($line, ' ?= ') !== false) {
2017-03-11 19:55:56 +01:00
continue;
}
2020-01-31 19:29:43 +01:00
$line = \preg_replace(['/[(]([\\w\\.]+) ([\\w\\.]+)[)]/', '/\\s+/'], ['$1<$2>', ' '], $line);
2019-12-14 16:47:04 +01:00
if (\strpos($line, ';') === false) {
$lineBuf .= $line;
continue;
} elseif ($lineBuf) {
$lineBuf .= $line;
$line = $lineBuf;
$lineBuf = '';
}
2019-12-14 18:31:28 +01:00
$name = \preg_replace(['/#.*/', '/\\s.*/'], '', $line);
if (\in_array($name, ['bytes', 'int128', 'int256', 'int512', 'int', 'long', 'double', 'string', 'bytes', 'object', 'function'])) {
2019-12-16 21:14:57 +01:00
/*if (!(\in_array($scheme_type, ['ton_api', 'lite_api']) && $name === 'bytes')) {
2020-01-31 19:29:43 +01:00
continue;
}*/
2019-12-14 18:31:28 +01:00
continue;
}
2019-12-16 21:14:57 +01:00
if (\in_array($scheme_type, ['ton_api', 'lite_api'])) {
$clean = \preg_replace(['/;/', '/#[a-f0-9]+ /', '/ [a-zA-Z0-9_]+\\:flags\\.[0-9]+\\?true/', '/[<]/', '/[>]/', '/ /', '/^ /', '/ $/', '/{/', '/}/'], ['', ' ', '', ' ', ' ', ' ', '', '', '', ''], $line);
} else {
$clean = \preg_replace(['/:bytes /', '/;/', '/#[a-f0-9]+ /', '/ [a-zA-Z0-9_]+\\:flags\\.[0-9]+\\?true/', '/[<]/', '/[>]/', '/ /', '/^ /', '/ $/', '/\\?bytes /', '/{/', '/}/'], [':string ', '', ' ', '', ' ', ' ', ' ', '', '', '?string ', '', ''], $line);
}
2019-09-02 17:08:36 +02:00
$id = \hash('crc32b', $clean);
2020-01-31 19:29:43 +01:00
if (\preg_match('/^[^\\s]+#([a-f0-9]*)/i', $line, $matches)) {
2019-09-02 17:08:36 +02:00
$nid = \str_pad($matches[1], 8, '0', \STR_PAD_LEFT);
if ($id !== $nid) {
2019-10-31 20:48:06 +01:00
$this->API->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['crc32_mismatch'], $id, $nid, $line), \danog\MadelineProto\Logger::ERROR);
}
$id = $nid;
}
2019-09-02 17:08:36 +02:00
if (!\is_null($e)) {
2019-11-01 12:45:15 +01:00
$this->tdDescriptions[$type][$name] = ['description' => $e, 'params' => $dparams];
$e = null;
$dparams = [];
}
$TL_dict[$type][$key][$type === 'constructors' ? 'predicate' : 'method'] = $name;
2019-12-16 21:14:57 +01:00
$TL_dict[$type][$key]['id'] = $a = \strrev(\hex2bin($id));
$TL_dict[$type][$key]['params'] = [];
2019-09-02 17:08:36 +02:00
$TL_dict[$type][$key]['type'] = \preg_replace(['/.+\\s+=\\s+/', '/;/'], '', $line);
2017-03-11 19:55:56 +01:00
if ($layer !== null) {
$TL_dict[$type][$key]['layer'] = $layer;
}
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
if ($name !== 'vector' && $TL_dict[$type][$key]['type'] !== 'Vector t') {
2019-09-02 17:08:36 +02:00
foreach (\explode(' ', \preg_replace(['/^[^\\s]+\\s/', '/=\\s[^\\s]+/', '/\\s$/'], '', $line)) as $param) {
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
if ($param === '') {
continue;
}
if ($param[0] === '{') {
continue;
}
if ($param === '#') {
continue;
}
2019-09-02 17:08:36 +02:00
$explode = \explode(':', $param);
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
$TL_dict[$type][$key]['params'][] = ['name' => $explode[0], 'type' => $explode[1]];
2017-01-02 19:52:29 +01:00
}
}
$key++;
}
} else {
foreach ($TL_dict['constructors'] as $key => $value) {
2019-10-29 23:02:47 +01:00
$TL_dict['constructors'][$key]['id'] = \danog\MadelineProto\Tools::packSignedInt($TL_dict['constructors'][$key]['id']);
}
foreach ($TL_dict['methods'] as $key => $value) {
2019-10-29 23:02:47 +01:00
$TL_dict['methods'][$key]['id'] = \danog\MadelineProto\Tools::packSignedInt($TL_dict['methods'][$key]['id']);
}
}
2020-02-07 21:13:49 +01:00
if (empty($TL_dict) || empty($TL_dict['constructors']) || !isset($TL_dict['methods'])) {
2020-02-04 17:34:02 +01:00
throw new Exception(\danog\MadelineProto\Lang::$current_lang['src_file_invalid'].$file);
2017-01-02 19:52:29 +01:00
}
2019-10-31 20:48:06 +01:00
$this->API->logger->logger(\danog\MadelineProto\Lang::$current_lang['translating_obj'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
2016-11-18 21:50:19 +01:00
foreach ($TL_dict['constructors'] as $elem) {
2017-03-11 19:55:56 +01:00
if ($scheme_type === 'secret') {
2019-11-01 12:45:15 +01:00
$this->secretLayer = \max($this->secretLayer, $elem['layer']);
2017-03-11 19:55:56 +01:00
}
2019-12-11 16:22:34 +01:00
$this->{$scheme_type === 'td' ? 'tdConstructors' : 'constructors'}->add($elem, $scheme_type);
2016-11-18 21:50:19 +01:00
}
2019-10-31 20:48:06 +01:00
$this->API->logger->logger(\danog\MadelineProto\Lang::$current_lang['translating_methods'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
2016-11-18 21:50:19 +01:00
foreach ($TL_dict['methods'] as $elem) {
2019-12-11 16:22:34 +01:00
$this->{$scheme_type === 'td' ? 'tdMethods' : 'methods'}->add($elem);
2017-03-11 19:55:56 +01:00
if ($scheme_type === 'secret') {
2019-11-01 12:45:15 +01:00
$this->secretLayer = \max($this->secretLayer, $elem['layer']);
2017-03-11 19:55:56 +01:00
}
}
}
if (isset($files->getOther()['td'])) {
2019-11-01 12:45:15 +01:00
foreach ($this->tdConstructors->by_id as $id => $data) {
2017-08-18 18:10:30 +02:00
$name = $data['predicate'];
2019-10-29 21:33:23 +01:00
if ($this->constructors->findById($id) === false) {
2019-11-01 12:45:15 +01:00
unset($this->tdDescriptions['constructors'][$name]);
} else {
2019-11-01 12:45:15 +01:00
if (!\count($this->tdDescriptions['constructors'][$name]['params'])) {
2017-04-21 13:14:21 +02:00
continue;
}
2019-11-01 12:45:15 +01:00
foreach ($this->tdDescriptions['constructors'][$name]['params'] as $k => $param) {
$this->tdDescriptions['constructors'][$name]['params'][$k] = \str_replace('nullable', 'optional', $param);
}
}
}
2019-11-01 12:45:15 +01:00
foreach ($this->tdMethods->by_id as $id => $data) {
2017-08-18 18:10:30 +02:00
$name = $data['method'];
2019-10-29 21:33:23 +01:00
if ($this->methods->findById($id) === false) {
2019-11-01 12:45:15 +01:00
unset($this->tdDescriptions['methods'][$name]);
} else {
2019-11-01 12:45:15 +01:00
foreach ($this->tdDescriptions['methods'][$name]['params'] as $k => $param) {
$this->tdDescriptions['constructors'][$name]['params'][$k] = \str_replace('nullable', 'optional', $param);
}
}
2016-11-18 21:50:19 +01:00
}
2016-06-23 23:51:08 +02:00
}
$files->upgrade();
2016-06-23 23:51:08 +02:00
}
2019-10-31 20:48:06 +01:00
/**
* Get TL namespaces.
*
* @return array
*/
public function getMethodNamespaces(): array
2017-01-27 22:05:24 +01:00
{
2017-08-23 14:53:24 +02:00
$res = [];
2017-08-23 15:54:15 +02:00
foreach ($this->methods->method_namespace as $pair) {
2019-09-02 17:08:36 +02:00
$a = \key($pair);
2017-08-23 16:50:21 +02:00
$res[$a] = $a;
2017-08-23 15:54:15 +02:00
}
2017-08-23 14:53:24 +02:00
return $res;
2017-01-27 20:04:42 +01:00
}
2019-10-31 20:48:06 +01:00
/**
* Get namespaced methods (method => namespace).
*
* @return array
*/
public function getMethodsNamespaced(): array
2017-06-26 15:57:03 +02:00
{
return $this->methods->method_namespace;
}
2019-10-31 20:48:06 +01:00
/**
* Update TL callbacks.
*
* @param TLCallback[] $objects TL callbacks
*
* @return void
*/
public function updateCallbacks(array $objects)
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-11-01 12:45:15 +01:00
$this->callbacks = [];
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
foreach ($objects as $object) {
2019-10-31 20:48:06 +01:00
if (!isset(\class_implements(\get_class($object))[TLCallback::class])) {
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
throw new Exception('Invalid callback object provided!');
}
2020-01-31 19:29:43 +01:00
$new = [TLCallback::METHOD_BEFORE_CALLBACK => $object->getMethodBeforeCallbacks(), TLCallback::METHOD_CALLBACK => $object->getMethodCallbacks(), TLCallback::CONSTRUCTOR_BEFORE_CALLBACK => $object->getConstructorBeforeCallbacks(), TLCallback::CONSTRUCTOR_CALLBACK => $object->getConstructorCallbacks(), TLCallback::CONSTRUCTOR_SERIALIZE_CALLBACK => $object->getConstructorSerializeCallbacks(), TLCallback::TYPE_MISMATCH_CALLBACK => $object->getTypeMismatchCallbacks()];
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
foreach ($new as $type => $values) {
foreach ($values as $match => $callback) {
2019-11-01 12:45:15 +01:00
if (!isset($this->callbacks[$type][$match])) {
$this->callbacks[$type][$match] = [];
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-09-02 17:08:36 +02:00
if (\in_array($type, [TLCallback::TYPE_MISMATCH_CALLBACK, TLCallback::CONSTRUCTOR_SERIALIZE_CALLBACK])) {
2019-11-01 12:45:15 +01:00
$this->callbacks[$type][$match] = $callback;
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-11-01 12:45:15 +01:00
$this->callbacks[$type][$match] = \array_merge($callback, $this->callbacks[$type][$match]);
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-31 20:48:06 +01:00
/**
* Deserialize bool.
*
* @param string $id Constructor ID
*
* @return bool
*/
private function deserializeBool(string $id): bool
2016-11-29 01:48:19 +01:00
{
2019-10-29 21:33:23 +01:00
$tl_elem = $this->constructors->findById($id);
if ($tl_elem === false) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['bool_error']);
}
return $tl_elem['predicate'] === 'boolTrue';
}
2019-10-31 20:48:06 +01:00
/**
* Serialize TL object.
*
* @param array $type TL type definition
* @param mixed $object Object to serialize
* @param string $ctx Context
* @param integer $layer Layer version
*
2020-10-01 21:36:07 +02:00
* @return \Generator
*
* @psalm-return \Generator<int|mixed, array|mixed, mixed, false|mixed|null|string>
2019-10-31 20:48:06 +01:00
*/
public function serializeObject(array $type, $object, $ctx, int $layer = -1): \Generator
2016-10-13 23:22:32 +02:00
{
switch ($type['type']) {
case 'int':
2019-09-02 17:08:36 +02:00
if (!\is_numeric($object)) {
if (\is_array($object) && $type['name'] === 'hash') {
2019-10-29 23:02:47 +01:00
$object = \danog\MadelineProto\Tools::genVectorHash($object);
2018-08-29 17:16:38 +02:00
} else {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['not_numeric']);
}
}
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools::packSignedInt($object);
case '#':
2019-09-02 17:08:36 +02:00
if (!\is_numeric($object)) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['not_numeric']);
}
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools::packUnsignedInt($object);
case 'long':
2019-09-02 17:08:36 +02:00
if (\is_object($object)) {
return \str_pad(\strrev($object->toBytes()), 8, \chr(0));
}
2019-09-02 17:08:36 +02:00
if (\is_string($object) && \strlen($object) === 8) {
return $object;
}
2019-09-02 17:08:36 +02:00
if (\is_string($object) && \strlen($object) === 9 && $object[0] === 'a') {
return \substr($object, 1);
}
2020-02-04 17:34:02 +01:00
if (\is_array($object) && \count($object) === 2) {
return \pack('l2', ...$object); // For bot API on 32bit
}
2019-09-02 17:08:36 +02:00
if (!\is_numeric($object)) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['not_numeric']);
}
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools::packSignedLong($object);
case 'int128':
2019-09-02 17:08:36 +02:00
if (\strlen($object) !== 16) {
2019-12-14 18:31:28 +01:00
$object = \base64_decode($object);
if (\strlen($object) !== 16) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['long_not_16']);
}
2017-03-11 19:55:56 +01:00
}
return (string) $object;
case 'int256':
2019-09-02 17:08:36 +02:00
if (\strlen($object) !== 32) {
2019-12-14 18:31:28 +01:00
$object = \base64_decode($object);
if (\strlen($object) !== 32) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['long_not_32']);
}
2017-03-11 19:55:56 +01:00
}
return (string) $object;
case 'int512':
2019-09-02 17:08:36 +02:00
if (\strlen($object) !== 64) {
2019-12-14 18:31:28 +01:00
$object = \base64_decode($object);
if (\strlen($object) !== 64) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['long_not_64']);
}
2017-03-11 19:55:56 +01:00
}
return (string) $object;
case 'double':
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools::packDouble($object);
case 'string':
2019-09-02 17:08:36 +02:00
if (!\is_string($object)) {
2017-09-06 19:26:49 +02:00
throw new Exception("You didn't provide a valid string");
}
2020-02-04 17:34:02 +01:00
//$object = \pack('C*', ...\unpack('C*', $object));
2019-09-02 17:08:36 +02:00
$l = \strlen($object);
2017-05-17 17:29:29 +02:00
$concat = '';
if ($l <= 253) {
2019-09-02 17:08:36 +02:00
$concat .= \chr($l);
2017-05-17 17:29:29 +02:00
$concat .= $object;
2020-02-04 17:34:02 +01:00
$concat .= \pack('@'.\danog\MadelineProto\Tools::posmod(-$l - 1, 4));
2017-05-17 17:29:29 +02:00
} else {
2019-09-02 17:08:36 +02:00
$concat .= \chr(254);
2019-10-29 23:02:47 +01:00
$concat .= \substr(\danog\MadelineProto\Tools::packSignedInt($l), 0, 3);
2017-05-17 17:29:29 +02:00
$concat .= $object;
2020-02-04 17:34:02 +01:00
$concat .= \pack('@'.\danog\MadelineProto\Tools::posmod(-$l, 4));
2017-05-17 17:29:29 +02:00
}
return $concat;
case 'bytes':
2019-09-02 17:08:36 +02:00
if (\is_array($object) && isset($object['_']) && $object['_'] === 'bytes') {
$object = \base64_decode($object['bytes']);
2018-04-19 19:18:31 +02:00
}
2019-09-02 17:08:36 +02:00
if (!\is_string($object) && !$object instanceof \danog\MadelineProto\TL\Types\Bytes) {
2017-09-06 19:26:49 +02:00
throw new Exception("You didn't provide a valid string");
}
2019-09-02 17:08:36 +02:00
$l = \strlen($object);
$concat = '';
if ($l <= 253) {
2019-09-02 17:08:36 +02:00
$concat .= \chr($l);
$concat .= $object;
2020-02-04 17:34:02 +01:00
$concat .= \pack('@'.\danog\MadelineProto\Tools::posmod(-$l - 1, 4));
} else {
2019-09-02 17:08:36 +02:00
$concat .= \chr(254);
2019-10-29 23:02:47 +01:00
$concat .= \substr(\danog\MadelineProto\Tools::packSignedInt($l), 0, 3);
$concat .= $object;
2020-02-04 17:34:02 +01:00
$concat .= \pack('@'.\danog\MadelineProto\Tools::posmod(-$l, 4));
}
return $concat;
case 'Bool':
2019-10-29 21:33:23 +01:00
return $this->constructors->findByPredicate((bool) $object ? 'boolTrue' : 'boolFalse')['id'];
case 'true':
return;
case '!X':
return $object;
case 'Vector t':
2019-09-02 17:08:36 +02:00
if (!\is_array($object)) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['array_invalid']);
2017-05-08 21:10:01 +02:00
}
if (isset($object['_'])) {
2020-02-04 17:34:02 +01:00
throw new Exception('You must provide an array of '.$type['subtype'].' objects, not a '.$type['subtype']." object. Example: [['_' => ".$type['subtype'].', ... ]]');
}
2019-10-29 21:33:23 +01:00
$concat = $this->constructors->findByPredicate('vector')['id'];
2019-10-29 23:02:47 +01:00
$concat .= \danog\MadelineProto\Tools::packUnsignedInt(\count($object));
foreach ($object as $k => $current_object) {
2020-10-19 18:48:59 +02:00
$concat .= (yield from $this->serializeObject(['type' => $type['subtype']], $current_object, $k, $layer));
}
return $concat;
case 'vector':
2019-09-02 17:08:36 +02:00
if (!\is_array($object)) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['array_invalid']);
}
2019-10-29 23:02:47 +01:00
$concat = \danog\MadelineProto\Tools::packUnsignedInt(\count($object));
foreach ($object as $k => $current_object) {
2020-10-19 18:48:59 +02:00
$concat .= (yield from $this->serializeObject(['type' => $type['subtype']], $current_object, $k, $layer));
}
return $concat;
case 'Object':
2019-09-02 17:08:36 +02:00
if (\is_string($object)) {
return $object;
}
}
2019-09-02 17:08:36 +02:00
if ($type['type'] === 'InputMessage' && !\is_array($object)) {
$object = ['_' => 'inputMessageID', 'id' => $object];
2019-11-01 12:45:15 +01:00
} elseif (isset($this->callbacks[TLCallback::TYPE_MISMATCH_CALLBACK][$type['type']]) && (!\is_array($object) || isset($object['_']) && $this->constructors->findByPredicate($object['_'])['type'] !== $type['type'])) {
2020-01-31 20:28:47 +01:00
$object = $this->callbacks[TLCallback::TYPE_MISMATCH_CALLBACK][$type['type']]($object);
$object = $object instanceof \Generator ? yield from $object : yield $object;
if (!isset($object[$type['type']])) {
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
throw new \danog\MadelineProto\Exception("Could not convert {$type['type']} object");
}
$object = $object[$type['type']];
}
if (!isset($object['_'])) {
2019-10-29 21:33:23 +01:00
$constructorData = $this->constructors->findByPredicate($type['type'], $layer);
if ($constructorData === false) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['predicate_not_set']);
}
$auto = true;
$object['_'] = $constructorData['predicate'];
}
2019-11-01 12:45:15 +01:00
if (isset($this->callbacks[TLCallback::CONSTRUCTOR_SERIALIZE_CALLBACK][$object['_']])) {
$object = yield $this->callbacks[TLCallback::CONSTRUCTOR_SERIALIZE_CALLBACK][$object['_']]($object);
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
}
$predicate = $object['_'];
2019-10-29 21:33:23 +01:00
$constructorData = $this->constructors->findByPredicate($predicate, $layer);
if ($constructorData === false) {
2019-10-31 20:48:06 +01:00
$this->API->logger->logger($object, \danog\MadelineProto\Logger::FATAL_ERROR);
2019-09-02 17:08:36 +02:00
throw new Exception(\sprintf(\danog\MadelineProto\Lang::$current_lang['type_extract_error'], $predicate));
}
if ($bare = $type['type'] != '' && $type['type'][0] === '%') {
2019-09-02 17:08:36 +02:00
$type['type'] = \substr($type['type'], 1);
}
2020-01-31 19:29:43 +01:00
if ($predicate === $type['type']) {
$bare = true;
}
if ($predicate === 'messageEntityMentionName') {
2019-10-29 21:33:23 +01:00
$constructorData = $this->constructors->findByPredicate('inputMessageEntityMentionName');
2017-03-11 19:55:56 +01:00
}
2019-12-15 13:21:57 +01:00
$concat = $bare ? '' : $constructorData['id'];
2020-10-19 18:48:59 +02:00
return $concat.(yield from $this->serializeParams($constructorData, $object, '', $layer, null));
}
2019-10-31 20:48:06 +01:00
/**
* Serialize method.
*
* @param string $method Method name
* @param mixed $arguments Arguments
*
2020-10-01 21:36:07 +02:00
* @return \Generator
*
* @psalm-return \Generator<int|mixed, Promise|Promise<\Amp\File\File>|Promise<\Amp\Ipc\Sync\ChannelledSocket>|Promise<int>|Promise<mixed>|Promise<null|string>|Promise<string>|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, string>
2019-10-31 20:48:06 +01:00
*/
public function serializeMethod(string $method, $arguments): \Generator
2016-07-14 15:15:50 +02:00
{
2019-10-29 21:33:23 +01:00
$tl = $this->methods->findByMethod($method);
if ($tl === false) {
2020-02-04 17:34:02 +01:00
throw new Exception(\danog\MadelineProto\Lang::$current_lang['method_not_found'].$method);
2016-06-26 12:59:15 +02:00
}
2020-10-19 18:48:59 +02:00
return $tl['id'].(yield from $this->serializeParams($tl, $arguments, $method, -1, $arguments['queuePromise'] ?? null));
}
2019-10-31 20:48:06 +01:00
/**
* Serialize parameters.
*
2020-04-05 14:57:33 +02:00
* @param array $tl TL object definition
* @param array $arguments Arguments
* @param string $ctx Context
* @param integer $layer Layer
2019-10-31 20:48:06 +01:00
*
2020-10-01 21:36:07 +02:00
* @return \Generator
*
* @psalm-return \Generator<int|mixed, Promise|Promise<\Amp\File\File>|Promise<\Amp\Ipc\Sync\ChannelledSocket>|Promise<int>|Promise<mixed>|Promise<null|string>|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, string>
2019-10-31 20:48:06 +01:00
*/
2020-10-19 18:48:59 +02:00
private function serializeParams(array $tl, $arguments, $ctx, int $layer, $promise): \Generator
{
$serialized = '';
2020-01-31 19:49:58 +01:00
$arguments = (yield from $this->API->botAPIToMTProto($arguments));
$flags = 0;
foreach ($tl['params'] as $cur_flag) {
2017-05-27 23:21:14 +02:00
if (isset($cur_flag['pow'])) {
switch ($cur_flag['type']) {
case 'true':
case 'false':
$flags = isset($arguments[$cur_flag['name']]) && $arguments[$cur_flag['name']] ? $flags | $cur_flag['pow'] : $flags & ~$cur_flag['pow'];
unset($arguments[$cur_flag['name']]);
break;
2016-11-23 13:58:38 +01:00
case 'Bool':
$arguments[$cur_flag['name']] = isset($arguments[$cur_flag['name']]) && $arguments[$cur_flag['name']] && ($flags & $cur_flag['pow']) != 0;
if (($flags & $cur_flag['pow']) === 0) {
2016-11-23 21:04:51 +01:00
unset($arguments[$cur_flag['name']]);
}
break;
default:
$flags = isset($arguments[$cur_flag['name']]) && $arguments[$cur_flag['name']] !== null ? $flags | $cur_flag['pow'] : $flags & ~$cur_flag['pow'];
2016-11-23 13:58:38 +01:00
break;
}
}
}
$arguments['flags'] = $flags;
foreach ($tl['params'] as $current_argument) {
if (!isset($arguments[$current_argument['name']])) {
2019-09-02 17:08:36 +02:00
if (isset($current_argument['pow']) && (\in_array($current_argument['type'], ['true', 'false']) || ($flags & $current_argument['pow']) === 0)) {
2019-10-31 20:48:06 +01:00
//$this->API->logger->logger('Skipping '.$current_argument['name'].' of type '.$current_argument['type');
2016-11-22 17:37:48 +01:00
continue;
}
if ($current_argument['name'] === 'random_bytes') {
2020-10-19 18:48:59 +02:00
$serialized .= yield from $this->serializeObject(['type' => 'bytes'], \danog\MadelineProto\Tools::random(15 + 4 * \danog\MadelineProto\Tools::randomInt($modulus = 3)), 'random_bytes');
continue;
}
2019-09-02 17:08:36 +02:00
if ($current_argument['name'] === 'data' && isset($tl['method']) && \in_array($tl['method'], ['messages.sendEncrypted', 'messages.sendEncryptedFile', 'messages.sendEncryptedService']) && isset($arguments['message'])) {
2020-10-19 18:48:59 +02:00
$serialized .= yield from $this->serializeObject($current_argument, yield from $this->API->encryptSecretMessage($arguments['peer']['chat_id'], $arguments['message'], $promise), 'data');
continue;
}
if ($current_argument['name'] === 'random_id') {
switch ($current_argument['type']) {
case 'long':
2019-10-29 23:02:47 +01:00
$serialized .= \danog\MadelineProto\Tools::random(8);
continue 2;
case 'int':
2019-10-29 23:02:47 +01:00
$serialized .= \danog\MadelineProto\Tools::random(4);
continue 2;
case 'Vector t':
if (isset($arguments['id'])) {
2019-10-29 21:33:23 +01:00
$serialized .= $this->constructors->findByPredicate('vector')['id'];
2019-10-29 23:02:47 +01:00
$serialized .= \danog\MadelineProto\Tools::packUnsignedInt(\count($arguments['id']));
$serialized .= \danog\MadelineProto\Tools::random(8 * \count($arguments['id']));
continue 2;
}
}
}
2018-08-29 17:16:38 +02:00
if ($current_argument['name'] === 'hash' && $current_argument['type'] === 'int') {
2019-09-02 17:08:36 +02:00
$serialized .= \pack('@4');
2018-08-29 17:16:38 +02:00
continue;
}
if ($tl['type'] === 'InputMedia' && $current_argument['name'] === 'mime_type') {
2020-01-31 19:29:43 +01:00
$serialized .= (yield from $this->serializeObject($current_argument, $arguments['file']['mime_type'], $current_argument['name'], $layer));
continue;
}
2019-09-02 17:08:36 +02:00
if ($tl['type'] === 'DocumentAttribute' && \in_array($current_argument['name'], ['w', 'h', 'duration'])) {
$serialized .= \pack('@4');
continue;
}
2019-09-02 17:08:36 +02:00
if (\in_array($current_argument['type'], ['bytes', 'string'])) {
$serialized .= \pack('@4');
2018-07-07 19:48:10 +02:00
continue;
}
2020-02-04 17:34:02 +01:00
if (($id = $this->constructors->findByPredicate(\lcfirst($current_argument['type']).'Empty', isset($tl['layer']) ? $tl['layer'] : -1)) && $id['type'] === $current_argument['type']) {
2018-08-31 14:25:28 +02:00
$serialized .= $id['id'];
continue;
}
2020-02-04 17:34:02 +01:00
if (($id = $this->constructors->findByPredicate('input'.$current_argument['type'].'Empty', isset($tl['layer']) ? $tl['layer'] : -1)) && $id['type'] === $current_argument['type']) {
$serialized .= $id['id'];
continue;
}
2019-07-23 13:07:54 +02:00
switch ($current_argument['type']) {
case 'Vector t':
case 'vector':
$arguments[$current_argument['name']] = [];
break;
}
2016-10-14 17:16:23 +02:00
}
2019-09-02 17:08:36 +02:00
if (\in_array($current_argument['type'], ['DataJSON', '%DataJSON'])) {
$arguments[$current_argument['name']] = ['_' => 'dataJSON', 'data' => \json_encode($arguments[$current_argument['name']])];
}
2019-09-02 17:08:36 +02:00
if (isset($current_argument['subtype']) && \in_array($current_argument['subtype'], ['DataJSON', '%DataJSON'])) {
\array_walk($arguments[$current_argument['name']], function (&$arg) {
$arg = ['_' => 'dataJSON', 'data' => \json_encode($arg)];
2018-04-17 10:40:34 +02:00
});
}
2020-01-31 19:29:43 +01:00
if ($current_argument['type'] === 'InputFile' && (!\is_array($arguments[$current_argument['name']]) || !(isset($arguments[$current_argument['name']]['_']) && $this->constructors->findByPredicate($arguments[$current_argument['name']]['_'])['type'] === 'InputFile'))) {
2020-01-31 19:49:58 +01:00
$arguments[$current_argument['name']] = (yield from $this->API->upload($arguments[$current_argument['name']]));
}
2019-10-29 21:33:23 +01:00
if ($current_argument['type'] === 'InputEncryptedChat' && (!\is_array($arguments[$current_argument['name']]) || isset($arguments[$current_argument['name']]['_']) && $this->constructors->findByPredicate($arguments[$current_argument['name']]['_'])['type'] !== $current_argument['type'])) {
2019-09-02 17:08:36 +02:00
if (\is_array($arguments[$current_argument['name']])) {
2020-01-31 19:49:58 +01:00
$arguments[$current_argument['name']] = (yield from $this->API->getInfo($arguments[$current_argument['name']]))['InputEncryptedChat'];
} else {
2019-10-31 20:48:06 +01:00
if (!$this->API->hasSecretChat($arguments[$current_argument['name']])) {
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['sec_peer_not_in_db']);
}
2019-10-31 20:48:06 +01:00
$arguments[$current_argument['name']] = $this->API->getSecretChat($arguments[$current_argument['name']])['InputEncryptedChat'];
}
}
2019-10-31 20:48:06 +01:00
//$this->API->logger->logger('Serializing '.$current_argument['name'].' of type '.$current_argument['type');
2020-01-31 19:29:43 +01:00
$serialized .= (yield from $this->serializeObject($current_argument, $arguments[$current_argument['name']], $current_argument['name'], $layer));
2016-06-23 23:51:08 +02:00
}
return $serialized;
}
2019-10-31 20:48:06 +01:00
/**
* Get length of TL payload.
*
* @param resource|string $stream Stream
* @param array $type Type identifier
2019-10-31 20:48:06 +01:00
*
* @return int
*/
public function getLength($stream, $type = ['type' => '']): int
2016-08-17 19:20:00 +02:00
{
2019-09-02 17:08:36 +02:00
if (\is_string($stream)) {
$res = \fopen('php://memory', 'rw+b');
\fwrite($res, $stream);
\fseek($res, 0);
$stream = $res;
2019-09-02 17:08:36 +02:00
} elseif (!\is_resource($stream)) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['stream_handle_invalid']);
2017-05-11 02:06:17 +02:00
}
$promises = [];
$this->deserializeInternal($stream, $promises, $type);
2019-09-02 17:08:36 +02:00
return \ftell($stream);
}
/**
2019-10-31 20:48:06 +01:00
* Deserialize TL object.
*
2020-04-05 22:22:47 +02:00
* @param string|resource $stream Stream
* @param array $type Type identifier
2019-10-31 20:48:06 +01:00
*
* @return array
* @psalm-return array{0: mixed, 1: \Amp\Promise}
*/
public function deserialize($stream, $type = ['type' => '']): array
{
$promises = [];
$result = $this->deserializeInternal($stream, $promises, $type);
return [
$result,
$promises ? Tools::all($promises) : null
];
}
/**
* Deserialize TL object.
*
* @param string|resource $stream Stream
* @param Promise[] &$promises Promise array
* @param array $type Type identifier
*
2019-10-31 20:48:06 +01:00
* @return mixed
2016-07-14 15:15:50 +02:00
*/
private function deserializeInternal($stream, array &$promises, array $type)
2016-07-14 15:15:50 +02:00
{
2019-09-02 17:08:36 +02:00
if (\is_string($stream)) {
$res = \fopen('php://memory', 'rw+b');
\fwrite($res, $stream);
\fseek($res, 0);
$stream = $res;
2019-09-02 17:08:36 +02:00
} elseif (!\is_resource($stream)) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['stream_handle_invalid']);
2016-08-06 12:14:40 +02:00
}
switch ($type['type']) {
case 'Bool':
2019-10-29 21:33:23 +01:00
return $this->deserializeBool(\stream_get_contents($stream, 4));
case 'int':
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools::unpackSignedInt(\stream_get_contents($stream, 4));
case '#':
2019-09-02 17:08:36 +02:00
return \unpack('V', \stream_get_contents($stream, 4))[1];
case 'long':
if (isset($type['idstrlong'])) {
2019-09-02 17:08:36 +02:00
return \stream_get_contents($stream, 8);
}
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Magic::$bigint || isset($type['strlong']) ? \stream_get_contents($stream, 8) : \danog\MadelineProto\Tools::unpackSignedLong(\stream_get_contents($stream, 8));
case 'double':
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools::unpackDouble(\stream_get_contents($stream, 8));
case 'int128':
2019-09-02 17:08:36 +02:00
return \stream_get_contents($stream, 16);
case 'int256':
2019-09-02 17:08:36 +02:00
return \stream_get_contents($stream, 32);
case 'int512':
2019-09-02 17:08:36 +02:00
return \stream_get_contents($stream, 64);
case 'string':
case 'bytes':
2019-09-02 17:08:36 +02:00
$l = \ord(\stream_get_contents($stream, 1));
2016-08-06 12:14:40 +02:00
if ($l > 254) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['length_too_big']);
2016-08-06 12:14:40 +02:00
}
if ($l === 254) {
2020-02-04 17:34:02 +01:00
$long_len = \unpack('V', \stream_get_contents($stream, 3).\chr(0))[1];
2019-09-02 17:08:36 +02:00
$x = \stream_get_contents($stream, $long_len);
2019-10-29 23:02:47 +01:00
$resto = \danog\MadelineProto\Tools::posmod(-$long_len, 4);
2016-08-14 20:00:30 +02:00
if ($resto > 0) {
2019-09-02 17:08:36 +02:00
\stream_get_contents($stream, $resto);
2016-08-14 20:00:30 +02:00
}
} else {
2019-09-02 17:08:36 +02:00
$x = $l ? \stream_get_contents($stream, $l) : '';
2019-10-29 23:02:47 +01:00
$resto = \danog\MadelineProto\Tools::posmod(-($l + 1), 4);
2016-08-14 20:00:30 +02:00
if ($resto > 0) {
2019-09-02 17:08:36 +02:00
\stream_get_contents($stream, $resto);
2016-08-14 20:00:30 +02:00
}
}
2019-09-02 17:08:36 +02:00
if (!\is_string($x)) {
2020-09-26 17:11:41 +02:00
throw new Exception("Generated value isn't a string");
2016-08-06 12:14:40 +02:00
}
return $type['type'] === 'bytes' ? new Types\Bytes($x) : $x;
case 'Vector t':
2019-09-02 17:08:36 +02:00
$id = \stream_get_contents($stream, 4);
2019-10-29 21:33:23 +01:00
$constructorData = $this->constructors->findById($id);
if ($constructorData === false) {
2019-10-29 21:33:23 +01:00
$constructorData = $this->methods->findById($id);
2020-02-04 17:34:02 +01:00
$constructorData['predicate'] = 'method_'.$constructorData['method'];
}
if ($constructorData === false) {
2019-09-02 17:08:36 +02:00
throw new Exception(\sprintf(\danog\MadelineProto\Lang::$current_lang['type_extract_error_id'], $type['type'], \bin2hex(\strrev($id))));
}
switch ($constructorData['predicate']) {
case 'gzip_packed':
return $this->deserializeInternal(
\gzdecode(
$this->deserializeInternal(
$stream,
$promises,
['type' => 'bytes', 'connection' => $type['connection']]
)
),
$promises,
['type' => '', 'connection' => $type['connection']]
);
case 'Vector t':
case 'vector':
break;
default:
2020-09-26 17:11:41 +02:00
throw new Exception('Invalid vector constructor: '.$constructorData['predicate']);
2016-08-06 12:14:40 +02:00
}
2020-01-31 19:29:43 +01:00
// no break
case 'vector':
2019-09-02 17:08:36 +02:00
$count = \unpack('V', \stream_get_contents($stream, 4))[1];
$result = [];
$type['type'] = $type['subtype'];
2016-11-17 18:43:52 +01:00
for ($i = 0; $i < $count; $i++) {
$result[] = $this->deserializeInternal($stream, $promises, $type);
}
return $result;
}
if ($type['type'] != '' && $type['type'][0] === '%') {
2019-09-02 17:08:36 +02:00
$checkType = \substr($type['type'], 1);
2019-10-29 21:33:23 +01:00
$constructorData = $this->constructors->findByType($checkType);
if ($constructorData === false) {
2020-02-04 17:34:02 +01:00
throw new Exception(\danog\MadelineProto\Lang::$current_lang['constructor_not_found'].$checkType);
}
} else {
2019-10-29 21:33:23 +01:00
$constructorData = $this->constructors->findByPredicate($type['type']);
if ($constructorData === false) {
2019-09-02 17:08:36 +02:00
$id = \stream_get_contents($stream, 4);
2019-10-29 21:33:23 +01:00
$constructorData = $this->constructors->findById($id);
if ($constructorData === false) {
2019-10-29 21:33:23 +01:00
$constructorData = $this->methods->findById($id);
if ($constructorData === false) {
2019-09-02 17:08:36 +02:00
throw new Exception(\sprintf(\danog\MadelineProto\Lang::$current_lang['type_extract_error_id'], $type['type'], \bin2hex(\strrev($id))));
}
2020-02-04 17:34:02 +01:00
$constructorData['predicate'] = 'method_'.$constructorData['method'];
}
}
}
2019-12-14 18:31:28 +01:00
//var_dump($constructorData);
if ($constructorData['predicate'] === 'gzip_packed') {
2017-04-05 02:10:13 +02:00
if (!isset($type['subtype'])) {
$type['subtype'] = '';
}
return $this->deserializeInternal(
\gzdecode(
$this->deserializeInternal(
$stream,
$promises,
['type' => 'bytes']
)
),
$promises,
['type' => '', 'connection' => $type['connection'], 'subtype' => $type['subtype']]
);
}
if ($constructorData['type'] === 'Vector t') {
2019-09-02 14:37:30 +02:00
$constructorData['connection'] = $type['connection'];
2020-01-05 18:29:36 +01:00
$constructorData['subtype'] = $type['subtype'] ?? '';
$constructorData['type'] = 'vector';
return $this->deserializeInternal($stream, $promises, $constructorData);
}
if ($constructorData['predicate'] === 'boolTrue') {
return true;
}
if ($constructorData['predicate'] === 'boolFalse') {
return false;
2017-05-18 12:13:05 +02:00
}
$x = ['_' => $constructorData['predicate']];
2019-11-01 12:45:15 +01:00
if (isset($this->callbacks[TLCallback::CONSTRUCTOR_BEFORE_CALLBACK][$x['_']])) {
foreach ($this->callbacks[TLCallback::CONSTRUCTOR_BEFORE_CALLBACK][$x['_']] as $callback) {
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
$callback($x['_']);
}
}
foreach ($constructorData['params'] as $arg) {
2017-05-27 23:21:14 +02:00
if (isset($arg['pow'])) {
switch ($arg['type']) {
case 'true':
case 'false':
2017-01-14 12:53:50 +01:00
$x[$arg['name']] = ($x['flags'] & $arg['pow']) !== 0;
continue 2;
case 'Bool':
if (($x['flags'] & $arg['pow']) === 0) {
$x[$arg['name']] = false;
continue 2;
}
2020-01-31 19:29:43 +01:00
// no break
default:
if (($x['flags'] & $arg['pow']) === 0) {
continue 2;
}
}
}
2019-09-02 17:08:36 +02:00
if (\in_array($arg['name'], ['msg_ids', 'msg_id', 'bad_msg_id', 'req_msg_id', 'answer_msg_id', 'first_msg_id'])) {
$arg['idstrlong'] = true;
}
2019-09-02 17:08:36 +02:00
if (\in_array($arg['name'], ['key_fingerprint', 'server_salt', 'new_server_salt', 'server_public_key_fingerprints', 'ping_id', 'exchange_id'])) {
$arg['strlong'] = true;
}
2019-09-02 17:08:36 +02:00
if (\in_array($arg['name'], ['peer_tag', 'file_token', 'cdn_key', 'cdn_iv'])) {
2017-07-22 01:02:27 +02:00
$arg['type'] = 'string';
}
if ($x['_'] === 'rpc_result' && $arg['name'] === 'result' && isset($type['connection']->outgoing_messages[$x['req_msg_id']])) {
/** @var OutgoingMessage */
$message = $type['connection']->outgoing_messages[$x['req_msg_id']];
foreach ($this->callbacks[TLCallback::METHOD_BEFORE_CALLBACK][$message->getConstructor()] ?? [] as $callback) {
$callback($type['connection']->outgoing_messages[$x['req_msg_id']]['_']);
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
}
if ($message->getType() && \stripos($message->getType(), '<') !== false) {
$arg['subtype'] = \str_replace(['Vector<', '>'], '', $message->getType());
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-09-02 15:30:29 +02:00
if (isset($type['connection'])) {
$arg['connection'] = $type['connection'];
2017-04-05 13:20:26 +02:00
}
$x[$arg['name']] = $this->deserializeInternal($stream, $promises, $arg);
if ($arg['name'] === 'random_bytes') {
2019-09-02 17:08:36 +02:00
if (\strlen($x[$arg['name']]) < 15) {
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['rand_bytes_too_small']);
2017-03-31 17:36:55 +02:00
}
2019-09-02 17:08:36 +02:00
unset($x[$arg['name']]);
}
}
if (isset($x['flags'])) {
// I don't think we need this anymore
unset($x['flags']);
2016-06-23 23:51:08 +02:00
}
if ($x['_'] === 'dataJSON') {
2019-09-02 17:08:36 +02:00
return \json_decode($x['data'], true);
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
} elseif ($constructorData['type'] === 'JSONValue') {
switch ($x['_']) {
case 'jsonNull':
return;
case 'jsonObject':
$res = [];
foreach ($x['value'] as $pair) {
$res[$pair['key']] = $pair['value'];
}
return $res;
default:
return $x['value'];
}
} elseif ($x['_'] === 'photoStrippedSize') {
$x['inflated'] = new Types\Bytes(Tools::inflateStripped($x['bytes']));
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-11-01 12:45:15 +01:00
if (isset($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']])) {
foreach ($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']] as $callback) {
$promise = \danog\MadelineProto\Tools::callFork($callback($x));
if ($promise instanceof Promise) {
$promises []= $promise;
}
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
}
} elseif ($x['_'] === 'rpc_result'
&& isset($type['connection']->outgoing_messages[$x['req_msg_id']])
&& isset($this->callbacks[TLCallback::METHOD_CALLBACK][$type['connection']->outgoing_messages[$x['req_msg_id']]->getConstructor()])) {
foreach ($this->callbacks[TLCallback::METHOD_CALLBACK][$type['connection']->outgoing_messages[$x['req_msg_id']]->getConstructor()] as $callback) {
2019-09-02 14:37:30 +02:00
$callback($type['connection']->outgoing_messages[$x['req_msg_id']], $x['result']);
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
}
}
if ($x['_'] === 'message' && isset($x['reply_markup']['rows'])) {
foreach ($x['reply_markup']['rows'] as $key => $row) {
foreach ($row['buttons'] as $bkey => $button) {
2019-12-14 17:59:34 +01:00
$x['reply_markup']['rows'][$key]['buttons'][$bkey] = new Types\Button($this->API, $x, $button);
}
}
}
return $x;
2016-06-23 23:51:08 +02:00
}
2018-02-24 17:54:39 +01:00
}