2016-06-23 23:51:08 +02:00
< ? php
2018-02-24 17:54:13 +01:00
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
/**
* 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
2020-09-12 13:50:49 +02:00
use Amp\Promise ;
2019-10-31 15:06:25 +01:00
use danog\MadelineProto\MTProto ;
2020-10-18 14:46:34 +02:00
use danog\MadelineProto\MTProto\OutgoingMessage ;
2020-09-22 11:48:12 +02:00
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 .
*
2020-09-22 11:48:12 +02:00
* @ param TLSchema $files Scheme files
2019-10-31 20:48:06 +01:00
* @ param TLCallback [] $objects TL Callback objects
*
* @ return void
*/
2020-09-22 11:48:12 +02:00
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 ([
2020-09-22 11:48:12 +02:00
'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 );
2017-01-27 13:19:16 +01:00
if ( $TL_dict === null ) {
2017-03-11 19:54:51 +01:00
$TL_dict = [ 'methods' => [], 'constructors' => []];
2017-01-02 19:50:37 +01:00
$type = 'constructors' ;
2017-03-11 19:54:51 +01:00
$layer = null ;
2019-09-02 17:08:36 +02:00
$tl_file = \explode ( " \n " , $filec );
2017-01-02 19:50:37 +01:00
$key = 0 ;
2017-03-11 19:54:51 +01:00
$e = null ;
$class = null ;
$dparams = [];
2019-12-14 16:47:04 +01:00
$lineBuf = '' ;
2020-09-22 11:48:12 +02:00
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 ));
2017-03-11 19:54:51 +01:00
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 );
2017-03-11 19:54:51 +01:00
if ( $elem [ 0 ] === 'class' ) {
2019-09-02 17:08:36 +02:00
$elem = \explode ( ' ' , $elem [ 1 ], 2 );
2017-03-11 19:54:51 +01:00
$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 ];
2017-03-11 19:54:51 +01:00
$class = null ;
2017-03-11 19:55:56 +01:00
} else {
$e = $elem [ 1 ];
}
2017-03-11 19:54:51 +01:00
continue ;
}
2017-03-11 19:55:56 +01:00
if ( $elem [ 0 ] === 'param_description' ) {
$elem [ 0 ] = 'description' ;
}
$dparams [ $elem [ 0 ]] = $elem [ 1 ];
2017-03-11 19:54:51 +01:00
}
continue ;
}
2019-09-02 17:08:36 +02:00
$line = \preg_replace ([ '|//.*|' , '|^\\s+$|' ], '' , $line );
2017-01-27 13:19:16 +01:00
if ( $line === '' ) {
2017-01-02 19:52:29 +01:00
continue ;
}
2017-01-27 13:19:16 +01:00
if ( $line === '---functions---' ) {
2017-01-02 19:52:29 +01:00
$type = 'methods' ;
continue ;
}
2017-01-27 13:19:16 +01:00
if ( $line === '---types---' ) {
2017-01-25 23:16:22 +01:00
$type = 'constructors' ;
continue ;
}
2020-01-31 19:29:43 +01:00
if ( \preg_match ( '|^===(\\d*)===|' , $line , $matches )) {
2018-03-04 00:41:26 +01:00
$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 );
2020-09-22 11:48:12 +02:00
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 );
2017-03-11 19:54:51 +01:00
}
2017-03-26 19:29:52 +02:00
$id = $nid ;
2017-03-11 19:54:51 +01:00
}
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 ];
2017-03-11 19:54:51 +01:00
$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 ));
2017-01-02 19:50:37 +01:00
$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
}
2017-01-02 19:50:37 +01:00
}
$key ++ ;
}
2017-05-16 15:12:04 +02:00
} 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' ]);
2017-05-16 15:12:04 +02:00
}
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' ]);
2017-05-16 15:12:04 +02:00
}
2017-01-02 19:50:37 +01:00
}
2020-02-07 21:13:49 +01:00
2017-03-11 19:54:51 +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
}
2017-03-11 19:54:51 +01:00
}
}
2020-09-22 11:48:12 +02: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 ]);
2017-03-11 19:54:51 +01:00
} 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 );
2017-03-11 19:54:51 +01:00
}
}
}
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 ]);
2017-03-11 19:54:51 +01:00
} 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 );
2017-03-11 19:54:51 +01:00
}
}
2016-11-18 21:50:19 +01:00
}
2016-06-23 23:51:08 +02:00
}
2020-09-22 11:48:12 +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 );
2016-11-29 01:47:59 +01:00
if ( $tl_elem === false ) {
2017-10-01 18:37:24 +02:00
throw new Exception ( \danog\MadelineProto\Lang :: $current_lang [ 'bool_error' ]);
2016-11-29 01:47:59 +01:00
}
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
{
2016-11-29 01:47:59 +01: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' ]);
}
2016-11-29 01:47:59 +01:00
}
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools :: packSignedInt ( $object );
2016-11-29 01:47:59 +01:00
case '#' :
2019-09-02 17:08:36 +02:00
if ( ! \is_numeric ( $object )) {
2017-10-01 18:37:24 +02:00
throw new Exception ( \danog\MadelineProto\Lang :: $current_lang [ 'not_numeric' ]);
2016-11-29 01:47:59 +01:00
}
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools :: packUnsignedInt ( $object );
2016-11-29 01:47:59 +01:00
case 'long' :
2019-09-02 17:08:36 +02:00
if ( \is_object ( $object )) {
return \str_pad ( \strrev ( $object -> toBytes ()), 8 , \chr ( 0 ));
2017-03-24 21:01:08 +01:00
}
2019-09-02 17:08:36 +02:00
if ( \is_string ( $object ) && \strlen ( $object ) === 8 ) {
2017-03-24 21:01:08 +01:00
return $object ;
}
2019-09-02 17:08:36 +02:00
if ( \is_string ( $object ) && \strlen ( $object ) === 9 && $object [ 0 ] === 'a' ) {
return \substr ( $object , 1 );
2017-05-16 15:12:04 +02:00
}
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 )) {
2017-10-01 18:37:24 +02:00
throw new Exception ( \danog\MadelineProto\Lang :: $current_lang [ 'not_numeric' ]);
2016-11-29 01:47:59 +01:00
}
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools :: packSignedLong ( $object );
2016-11-29 01:47:59 +01:00
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
}
2017-03-11 19:54:51 +01:00
return ( string ) $object ;
2016-11-29 01:47:59 +01:00
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
}
2017-03-11 19:54:51 +01:00
return ( string ) $object ;
2016-11-29 01:47:59 +01:00
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
}
2016-11-29 01:47:59 +01:00
return ( string ) $object ;
case 'double' :
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools :: packDouble ( $object );
2016-11-29 01:47:59 +01:00
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 ;
2016-11-29 01:47:59 +01:00
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 );
2016-11-29 01:47:59 +01:00
$concat = '' ;
if ( $l <= 253 ) {
2019-09-02 17:08:36 +02:00
$concat .= \chr ( $l );
2016-11-29 01:47:59 +01:00
$concat .= $object ;
2020-02-04 17:34:02 +01:00
$concat .= \pack ( '@' . \danog\MadelineProto\Tools :: posmod ( - $l - 1 , 4 ));
2016-11-29 01:47:59 +01: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 );
2016-11-29 01:47:59 +01:00
$concat .= $object ;
2020-02-04 17:34:02 +01:00
$concat .= \pack ( '@' . \danog\MadelineProto\Tools :: posmod ( - $l , 4 ));
2016-11-29 01:47:59 +01:00
}
return $concat ;
case 'Bool' :
2019-10-29 21:33:23 +01:00
return $this -> constructors -> findByPredicate (( bool ) $object ? 'boolTrue' : 'boolFalse' )[ 'id' ];
2016-11-29 01:47:59 +01:00
case 'true' :
return ;
case '!X' :
return $object ;
case 'Vector t' :
2019-09-02 17:08:36 +02:00
if ( ! \is_array ( $object )) {
2017-10-01 18:37:24 +02:00
throw new Exception ( \danog\MadelineProto\Lang :: $current_lang [ 'array_invalid' ]);
2017-05-08 21:10:01 +02:00
}
2018-06-29 13:50:14 +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' ] . ', ... ]]' );
2018-06-29 13:50:14 +02:00
}
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 ));
2017-07-26 08:30:48 +02:00
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 ));
2016-11-29 01:47:59 +01:00
}
2018-02-18 14:18:18 +01:00
return $concat ;
case 'vector' :
2019-09-02 17:08:36 +02:00
if ( ! \is_array ( $object )) {
2018-02-18 14:18:18 +01:00
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 ));
2018-02-18 14:18:18 +01:00
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 ));
2018-02-18 14:18:18 +01:00
}
2016-11-29 01:47:59 +01:00
return $concat ;
2018-02-18 14:18:18 +01:00
case 'Object' :
2019-09-02 17:08:36 +02:00
if ( \is_string ( $object )) {
2018-02-18 14:18:18 +01:00
return $object ;
}
2016-11-29 01:47:59 +01:00
}
2019-09-02 17:08:36 +02:00
if ( $type [ 'type' ] === 'InputMessage' && ! \is_array ( $object )) {
2018-03-08 12:28:03 +01:00
$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 ;
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
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 " );
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
}
$object = $object [ $type [ 'type' ]];
}
2016-11-29 01:47:59 +01:00
if ( ! isset ( $object [ '_' ])) {
2019-10-29 21:33:23 +01:00
$constructorData = $this -> constructors -> findByPredicate ( $type [ 'type' ], $layer );
2016-11-29 01:47:59 +01:00
if ( $constructorData === false ) {
2017-10-01 18:37:24 +02:00
throw new Exception ( \danog\MadelineProto\Lang :: $current_lang [ 'predicate_not_set' ]);
2016-11-29 01:47:59 +01:00
}
$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
}
2016-11-29 01:47:59 +01:00
$predicate = $object [ '_' ];
2019-10-29 21:33:23 +01:00
$constructorData = $this -> constructors -> findByPredicate ( $predicate , $layer );
2016-11-29 01:47:59 +01:00
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 ));
2016-10-13 23:22:11 +02:00
}
2018-02-24 17:54:13 +01:00
if ( $bare = $type [ 'type' ] != '' && $type [ 'type' ][ 0 ] === '%' ) {
2019-09-02 17:08:36 +02:00
$type [ 'type' ] = \substr ( $type [ 'type' ], 1 );
2016-11-29 01:47:59 +01:00
}
2020-01-31 19:29:43 +01:00
if ( $predicate === $type [ 'type' ]) {
2016-11-29 01:47:59 +01:00
$bare = true ;
}
2018-02-18 14:18:18 +01:00
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 ));
2016-11-29 01:47:59 +01:00
}
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 );
2016-11-29 01:47:59 +01:00
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 ));
2016-11-23 21:04:29 +01:00
}
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
2017-02-16 04:55:10 +01:00
{
$serialized = '' ;
2020-01-31 19:49:58 +01:00
$arguments = ( yield from $this -> API -> botAPIToMTProto ( $arguments ));
2016-11-22 13:13:29 +01:00
$flags = 0 ;
2016-11-23 21:04:29 +01:00
foreach ( $tl [ 'params' ] as $cur_flag ) {
2017-05-27 23:21:14 +02:00
if ( isset ( $cur_flag [ 'pow' ])) {
2016-11-22 13:13:29 +01:00
switch ( $cur_flag [ 'type' ]) {
case 'true' :
case 'false' :
2018-02-24 17:54:13 +01:00
$flags = isset ( $arguments [ $cur_flag [ 'name' ]]) && $arguments [ $cur_flag [ 'name' ]] ? $flags | $cur_flag [ 'pow' ] : $flags & ~ $cur_flag [ 'pow' ];
2016-11-22 13:13:29 +01:00
unset ( $arguments [ $cur_flag [ 'name' ]]);
break ;
2016-11-23 13:58:38 +01:00
case 'Bool' :
2018-02-24 17:54:13 +01:00
$arguments [ $cur_flag [ 'name' ]] = isset ( $arguments [ $cur_flag [ 'name' ]]) && $arguments [ $cur_flag [ 'name' ]] && ( $flags & $cur_flag [ 'pow' ]) != 0 ;
2017-01-27 13:19:16 +01:00
if (( $flags & $cur_flag [ 'pow' ]) === 0 ) {
2016-11-23 21:04:51 +01:00
unset ( $arguments [ $cur_flag [ 'name' ]]);
}
2016-11-22 13:13:29 +01:00
break ;
default :
2018-02-24 17:54:13 +01:00
$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 ;
2016-11-22 13:13:29 +01:00
}
}
}
$arguments [ 'flags' ] = $flags ;
2016-11-23 21:04:29 +01:00
foreach ( $tl [ 'params' ] as $current_argument ) {
Added APIFactory for calling namespaced mtproto methods, cleaned up testing.php and API.php, moved authorization keys, session_id, seq_no and time delta to the Connection class, added close_and_reopen method to the Connection class, improved DataCenter class, renamed Logging class to Logger, added a bit more logging, added setup_logger, switch_dc, init_authorization methods to the MTProto class, added parameter to disable automatic switching to nearest DC in write_client_info, added a try catch block in the create_auth_key method, fixed switching of DCs in wait_for_response method, added arguments check in the method calling methods, added a message id check in MessageHandler, added method_name_namespaced array in TL for APIFactory, renamed a lot of stuff and removed a few checks in the TL class, moved sendCode test call to testing.php
2016-11-16 15:05:27 +01:00
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 ;
}
2017-03-11 19:54:51 +01:00
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' );
2017-03-11 19:54:51 +01:00
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' );
2017-03-11 19:54:51 +01:00
continue ;
}
2017-01-27 13:19:16 +01:00
if ( $current_argument [ 'name' ] === 'random_id' ) {
2016-12-23 21:06:38 +01:00
switch ( $current_argument [ 'type' ]) {
case 'long' :
2019-10-29 23:02:47 +01:00
$serialized .= \danog\MadelineProto\Tools :: random ( 8 );
2016-12-23 21:06:38 +01:00
continue 2 ;
2016-12-30 16:32:25 +01:00
case 'int' :
2019-10-29 23:02:47 +01:00
$serialized .= \danog\MadelineProto\Tools :: random ( 4 );
2016-12-23 21:06:38 +01:00
continue 2 ;
case 'Vector t' :
2016-12-30 16:32:25 +01:00
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' ]));
2016-12-23 21:06:38 +01:00
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 ;
}
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
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 ));
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
continue ;
}
2019-09-02 17:08:36 +02:00
if ( $tl [ 'type' ] === 'DocumentAttribute' && \in_array ( $current_argument [ 'name' ], [ 'w' , 'h' , 'duration' ])) {
$serialized .= \pack ( '@4' );
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
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' ]) {
2018-02-18 14:18:18 +01:00
$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' ]])];
2017-04-06 22:15:59 +02:00
}
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
});
2018-04-17 10:39:55 +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' ]]));
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
}
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' ];
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
} else {
2019-10-31 20:48:06 +01:00
if ( ! $this -> API -> hasSecretChat ( $arguments [ $current_argument [ 'name' ]])) {
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
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' ];
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
}
}
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
}
Added APIFactory for calling namespaced mtproto methods, cleaned up testing.php and API.php, moved authorization keys, session_id, seq_no and time delta to the Connection class, added close_and_reopen method to the Connection class, improved DataCenter class, renamed Logging class to Logger, added a bit more logging, added setup_logger, switch_dc, init_authorization methods to the MTProto class, added parameter to disable automatic switching to nearest DC in write_client_info, added a try catch block in the create_auth_key method, fixed switching of DCs in wait_for_response method, added arguments check in the method calling methods, added a message id check in MessageHandler, added method_name_namespaced array in TL for APIFactory, renamed a lot of stuff and removed a few checks in the TL class, moved sendCode test call to testing.php
2016-11-16 15:05:27 +01:00
return $serialized ;
2016-07-14 14:22:46 +02:00
}
2019-10-31 20:48:06 +01:00
/**
* Get length of TL payload .
*
2020-10-04 16:27:22 +02:00
* @ 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 );
2017-05-18 12:12:33 +02:00
$stream = $res ;
2019-09-02 17:08:36 +02:00
} elseif ( ! \is_resource ( $stream )) {
2017-10-01 18:37:24 +02:00
throw new Exception ( \danog\MadelineProto\Lang :: $current_lang [ 'stream_handle_invalid' ]);
2017-05-11 02:06:17 +02:00
}
2020-09-12 13:50:49 +02:00
$promises = [];
$this -> deserializeInternal ( $stream , $promises , $type );
2019-09-02 17:08:36 +02:00
return \ftell ( $stream );
2016-08-17 19:19:43 +02:00
}
2016-07-14 14:22:46 +02:00
/**
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
*
2020-10-18 14:46:34 +02:00
* @ return array
* @ psalm - return array { 0 : mixed , 1 : \Amp\Promise }
2020-09-12 13:50:49 +02:00
*/
2020-10-18 14:46:34 +02:00
public function deserialize ( $stream , $type = [ 'type' => '' ]) : array
2020-09-12 13:50:49 +02:00
{
$promises = [];
$result = $this -> deserializeInternal ( $stream , $promises , $type );
2020-10-18 14:46:34 +02:00
return [
$result ,
$promises ? Tools :: all ( $promises ) : null
];
2020-09-12 13:50:49 +02:00
}
/**
* 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
*/
2020-09-12 13:50:49 +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 );
2017-05-18 12:12:33 +02:00
$stream = $res ;
2019-09-02 17:08:36 +02:00
} elseif ( ! \is_resource ( $stream )) {
2017-10-01 18:37:24 +02:00
throw new Exception ( \danog\MadelineProto\Lang :: $current_lang [ 'stream_handle_invalid' ]);
2016-08-06 12:14:40 +02:00
}
2016-11-29 01:47:59 +01:00
switch ( $type [ 'type' ]) {
2016-11-23 21:04:29 +01:00
case 'Bool' :
2019-10-29 21:33:23 +01:00
return $this -> deserializeBool ( \stream_get_contents ( $stream , 4 ));
2016-07-18 17:11:37 +02:00
case 'int' :
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools :: unpackSignedInt ( \stream_get_contents ( $stream , 4 ));
2016-07-18 17:11:37 +02:00
case '#' :
2019-09-02 17:08:36 +02:00
return \unpack ( 'V' , \stream_get_contents ( $stream , 4 ))[ 1 ];
2016-07-18 17:11:37 +02:00
case 'long' :
2017-05-16 15:12:04 +02:00
if ( isset ( $type [ 'idstrlong' ])) {
2019-09-02 17:08:36 +02:00
return \stream_get_contents ( $stream , 8 );
2017-05-16 15:12:04 +02:00
}
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 ));
2016-07-18 17:11:37 +02:00
case 'double' :
2019-10-29 23:02:47 +01:00
return \danog\MadelineProto\Tools :: unpackDouble ( \stream_get_contents ( $stream , 8 ));
2016-07-18 17:11:37 +02:00
case 'int128' :
2019-09-02 17:08:36 +02:00
return \stream_get_contents ( $stream , 16 );
2016-07-18 17:11:37 +02:00
case 'int256' :
2019-09-02 17:08:36 +02:00
return \stream_get_contents ( $stream , 32 );
2016-11-29 01:47:59 +01:00
case 'int512' :
2019-09-02 17:08:36 +02:00
return \stream_get_contents ( $stream , 64 );
2016-07-18 17:11:37 +02:00
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 ) {
2017-10-01 18:37:24 +02:00
throw new Exception ( \danog\MadelineProto\Lang :: $current_lang [ 'length_too_big' ]);
2016-08-06 12:14:40 +02:00
}
2017-01-27 13:19:16 +01: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
}
2016-07-14 14:22:46 +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
}
2016-07-18 17:11:37 +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
}
2018-02-24 17:54:13 +01:00
return $type [ 'type' ] === 'bytes' ? new Types\Bytes ( $x ) : $x ;
2016-11-29 01:47:59 +01:00
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 );
2018-02-18 14:18:18 +01:00
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' ];
2018-02-18 14:18:18 +01:00
}
2016-11-29 01:47:59 +01:00
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 ))));
2016-11-29 01:47:59 +01:00
}
switch ( $constructorData [ 'predicate' ]) {
case 'gzip_packed' :
2020-09-12 13:50:49 +02:00
return $this -> deserializeInternal (
\gzdecode (
$this -> deserializeInternal (
$stream ,
$promises ,
[ 'type' => 'bytes' , 'connection' => $type [ 'connection' ]]
)
),
$promises ,
[ 'type' => '' , 'connection' => $type [ 'connection' ]]
);
2016-11-29 01:47:59 +01:00
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
2016-11-29 01:47:59 +01:00
case 'vector' :
2019-09-02 17:08:36 +02:00
$count = \unpack ( 'V' , \stream_get_contents ( $stream , 4 ))[ 1 ];
2016-11-29 01:47:59 +01:00
$result = [];
2017-03-24 21:01:08 +01:00
$type [ 'type' ] = $type [ 'subtype' ];
2016-11-17 18:43:52 +01:00
for ( $i = 0 ; $i < $count ; $i ++ ) {
2020-09-12 13:50:49 +02:00
$result [] = $this -> deserializeInternal ( $stream , $promises , $type );
2016-07-18 17:11:37 +02:00
}
2016-11-29 01:47:59 +01:00
return $result ;
}
2017-01-27 13:19:16 +01:00
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 );
2016-11-29 01:47:59 +01:00
if ( $constructorData === false ) {
2020-02-04 17:34:02 +01:00
throw new Exception ( \danog\MadelineProto\Lang :: $current_lang [ 'constructor_not_found' ] . $checkType );
2016-11-29 01:47:59 +01:00
}
} else {
2019-10-29 21:33:23 +01:00
$constructorData = $this -> constructors -> findByPredicate ( $type [ 'type' ]);
2016-11-29 01:47:59 +01:00
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 );
2016-11-29 01:47:59 +01:00
if ( $constructorData === false ) {
2019-10-29 21:33:23 +01:00
$constructorData = $this -> methods -> findById ( $id );
2018-02-18 14:18:18 +01:00
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 ))));
2018-02-18 14:18:18 +01:00
}
2020-02-04 17:34:02 +01:00
$constructorData [ 'predicate' ] = 'method_' . $constructorData [ 'method' ];
2016-07-14 14:22:46 +02:00
}
2016-11-29 01:47:59 +01:00
}
}
2019-12-14 18:31:28 +01:00
//var_dump($constructorData);
2017-01-27 13:19:16 +01:00
if ( $constructorData [ 'predicate' ] === 'gzip_packed' ) {
2017-04-05 02:10:13 +02:00
if ( ! isset ( $type [ 'subtype' ])) {
$type [ 'subtype' ] = '' ;
}
2020-09-12 13:50:49 +02:00
return $this -> deserializeInternal (
\gzdecode (
$this -> deserializeInternal (
$stream ,
$promises ,
[ 'type' => 'bytes' ]
)
),
$promises ,
[ 'type' => '' , 'connection' => $type [ 'connection' ], 'subtype' => $type [ 'subtype' ]]
);
2017-04-05 02:09:45 +02:00
}
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' ] ? ? '' ;
2017-04-05 02:09:45 +02:00
$constructorData [ 'type' ] = 'vector' ;
2020-09-12 13:50:49 +02:00
return $this -> deserializeInternal ( $stream , $promises , $constructorData );
2016-11-29 01:47:59 +01:00
}
2018-02-18 14:18:18 +01:00
if ( $constructorData [ 'predicate' ] === 'boolTrue' ) {
return true ;
}
if ( $constructorData [ 'predicate' ] === 'boolFalse' ) {
return false ;
2017-05-18 12:13:05 +02:00
}
2016-11-29 01:47:59 +01: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 [ '_' ]);
}
}
2016-11-29 01:47:59 +01:00
foreach ( $constructorData [ 'params' ] as $arg ) {
2017-05-27 23:21:14 +02:00
if ( isset ( $arg [ 'pow' ])) {
2016-11-29 01:47:59 +01:00
switch ( $arg [ 'type' ]) {
case 'true' :
case 'false' :
2017-01-14 12:53:50 +01:00
$x [ $arg [ 'name' ]] = ( $x [ 'flags' ] & $arg [ 'pow' ]) !== 0 ;
2016-11-29 01:47:59 +01:00
continue 2 ;
case 'Bool' :
2017-01-27 13:19:16 +01:00
if (( $x [ 'flags' ] & $arg [ 'pow' ]) === 0 ) {
2016-12-30 16:32:25 +01:00
$x [ $arg [ 'name' ]] = false ;
continue 2 ;
}
2020-01-31 19:29:43 +01:00
// no break
2016-11-29 01:47:59 +01:00
default :
2017-01-27 13:19:16 +01:00
if (( $x [ 'flags' ] & $arg [ 'pow' ]) === 0 ) {
2016-11-29 01:47:59 +01:00
continue 2 ;
2016-11-23 21:04:29 +01:00
}
2016-07-14 14:22:46 +02:00
}
2016-11-29 01:47:59 +01:00
}
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' ])) {
2017-05-16 15:12:04 +02:00
$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' ])) {
2017-03-24 21:01:08 +01:00
$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' ;
}
2020-10-18 14:46:34 +02:00
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
}
2020-10-18 14:46:34 +02: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
}
2017-04-05 02:09:45 +02: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
}
2020-09-12 13:50:49 +02:00
$x [ $arg [ 'name' ]] = $this -> deserializeInternal ( $stream , $promises , $arg );
2017-03-31 17:35:20 +02:00
if ( $arg [ 'name' ] === 'random_bytes' ) {
2019-09-02 17:08:36 +02:00
if ( \strlen ( $x [ $arg [ 'name' ]]) < 15 ) {
2017-10-01 18:37:24 +02:00
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' ]]);
2017-03-31 17:35:20 +02:00
}
2016-11-29 01:47:59 +01:00
}
2018-02-24 17:54:13 +01:00
if ( isset ( $x [ 'flags' ])) {
// I don't think we need this anymore
2016-11-29 01:47:59 +01:00
unset ( $x [ 'flags' ]);
2016-06-23 23:51:08 +02:00
}
2017-04-01 13:20:57 +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' ];
}
2020-06-23 20:30:40 +02:00
} elseif ( $x [ '_' ] === 'photoStrippedSize' ) {
2020-09-13 01:06:08 +02:00
$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 ) {
2020-09-12 13:50:49 +02:00
$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
}
2020-10-18 14:46:34 +02: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
}
2017-04-01 13:20:57 +02:00
}
2017-05-16 15:12:04 +02: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 );
2017-05-16 15:12:04 +02:00
}
}
}
2016-07-14 14:22:46 +02:00
return $x ;
2016-06-23 23:51:08 +02:00
}
2018-02-24 17:54:39 +01:00
}