More constants and a regression to fix bugs

This commit is contained in:
Daniil Gentili 2017-05-28 03:32:42 +01:00
parent 3aef7653a4
commit 7da8395234
7 changed files with 499 additions and 504 deletions

View File

@ -109,6 +109,48 @@ class MTProto extends \Volatile
const CONFIRMED = 2; const CONFIRMED = 2;
const READY = 3; const READY = 3;
const EMOJIS = ['๐Ÿ˜‰', '๐Ÿ˜', '๐Ÿ˜›', '๐Ÿ˜ญ', '๐Ÿ˜ฑ', '๐Ÿ˜ก', '๐Ÿ˜Ž', '๐Ÿ˜ด', '๐Ÿ˜ต', '๐Ÿ˜ˆ', '๐Ÿ˜ฌ', '๐Ÿ˜‡', '๐Ÿ˜', '๐Ÿ‘ฎ', '๐Ÿ‘ท', '๐Ÿ’‚', '๐Ÿ‘ถ', '๐Ÿ‘จ', '๐Ÿ‘ฉ', '๐Ÿ‘ด', '๐Ÿ‘ต', '๐Ÿ˜ป', '๐Ÿ˜ฝ', '๐Ÿ™€', '๐Ÿ‘บ', '๐Ÿ™ˆ', '๐Ÿ™‰', '๐Ÿ™Š', '๐Ÿ’€', '๐Ÿ‘ฝ', '๐Ÿ’ฉ', '๐Ÿ”ฅ', '๐Ÿ’ฅ', '๐Ÿ’ค', '๐Ÿ‘‚', '๐Ÿ‘€', '๐Ÿ‘ƒ', '๐Ÿ‘…', '๐Ÿ‘„', '๐Ÿ‘', '๐Ÿ‘Ž', '๐Ÿ‘Œ', '๐Ÿ‘Š', 'โœŒ', 'โœ‹', '๐Ÿ‘', '๐Ÿ‘†', '๐Ÿ‘‡', '๐Ÿ‘‰', '๐Ÿ‘ˆ', '๐Ÿ™', '๐Ÿ‘', '๐Ÿ’ช', '๐Ÿšถ', '๐Ÿƒ', '๐Ÿ’ƒ', '๐Ÿ‘ซ', '๐Ÿ‘ช', '๐Ÿ‘ฌ', '๐Ÿ‘ญ', '๐Ÿ’…', '๐ŸŽฉ', '๐Ÿ‘‘', '๐Ÿ‘’', '๐Ÿ‘Ÿ', '๐Ÿ‘ž', '๐Ÿ‘ ', '๐Ÿ‘•', '๐Ÿ‘—', '๐Ÿ‘–', '๐Ÿ‘™', '๐Ÿ‘œ', '๐Ÿ‘“', '๐ŸŽ€', '๐Ÿ’„', '๐Ÿ’›', '๐Ÿ’™', '๐Ÿ’œ', '๐Ÿ’š', '๐Ÿ’', '๐Ÿ’Ž', '๐Ÿถ', '๐Ÿบ', '๐Ÿฑ', '๐Ÿญ', '๐Ÿน', '๐Ÿฐ', '๐Ÿธ', '๐Ÿฏ', '๐Ÿจ', '๐Ÿป', '๐Ÿท', '๐Ÿฎ', '๐Ÿ—', '๐Ÿด', '๐Ÿ‘', '๐Ÿ˜', '๐Ÿผ', '๐Ÿง', '๐Ÿฅ', '๐Ÿ”', '๐Ÿ', '๐Ÿข', '๐Ÿ›', '๐Ÿ', '๐Ÿœ', '๐Ÿž', '๐ŸŒ', '๐Ÿ™', '๐Ÿš', '๐ŸŸ', '๐Ÿฌ', '๐Ÿ‹', '๐Ÿ', '๐ŸŠ', '๐Ÿซ', '๐Ÿ€', '๐ŸŒน', '๐ŸŒป', '๐Ÿ', '๐ŸŒพ', '๐Ÿ„', '๐ŸŒต', '๐ŸŒด', '๐ŸŒณ', '๐ŸŒž', '๐ŸŒš', '๐ŸŒ™', '๐ŸŒŽ', '๐ŸŒ‹', 'โšก', 'โ˜”', 'โ„', 'โ›„', '๐ŸŒ€', '๐ŸŒˆ', '๐ŸŒŠ', '๐ŸŽ“', '๐ŸŽ†', '๐ŸŽƒ', '๐Ÿ‘ป', '๐ŸŽ…', '๐ŸŽ„', '๐ŸŽ', '๐ŸŽˆ', '๐Ÿ”ฎ', '๐ŸŽฅ', '๐Ÿ“ท', '๐Ÿ’ฟ', '๐Ÿ’ป', 'โ˜Ž', '๐Ÿ“ก', '๐Ÿ“บ', '๐Ÿ“ป', '๐Ÿ”‰', '๐Ÿ””', 'โณ', 'โฐ', 'โŒš', '๐Ÿ”’', '๐Ÿ”‘', '๐Ÿ”Ž', '๐Ÿ’ก', '๐Ÿ”ฆ', '๐Ÿ”Œ', '๐Ÿ”‹', '๐Ÿšฟ', '๐Ÿšฝ', '๐Ÿ”ง', '๐Ÿ”จ', '๐Ÿšช', '๐Ÿšฌ', '๐Ÿ’ฃ', '๐Ÿ”ซ', '๐Ÿ”ช', '๐Ÿ’Š', '๐Ÿ’‰', '๐Ÿ’ฐ', '๐Ÿ’ต', '๐Ÿ’ณ', 'โœ‰', '๐Ÿ“ซ', '๐Ÿ“ฆ', '๐Ÿ“…', '๐Ÿ“', 'โœ‚', '๐Ÿ“Œ', '๐Ÿ“Ž', 'โœ’', 'โœ', '๐Ÿ“', '๐Ÿ“š', '๐Ÿ”ฌ', '๐Ÿ”ญ', '๐ŸŽจ', '๐ŸŽฌ', '๐ŸŽค', '๐ŸŽง', '๐ŸŽต', '๐ŸŽน', '๐ŸŽป', '๐ŸŽบ', '๐ŸŽธ', '๐Ÿ‘พ', '๐ŸŽฎ', '๐Ÿƒ', '๐ŸŽฒ', '๐ŸŽฏ', '๐Ÿˆ', '๐Ÿ€', 'โšฝ', 'โšพ', '๐ŸŽพ', '๐ŸŽฑ', '๐Ÿ‰', '๐ŸŽณ', '๐Ÿ', '๐Ÿ‡', '๐Ÿ†', '๐ŸŠ', '๐Ÿ„', 'โ˜•', '๐Ÿผ', '๐Ÿบ', '๐Ÿท', '๐Ÿด', '๐Ÿ•', '๐Ÿ”', '๐ŸŸ', '๐Ÿ—', '๐Ÿฑ', '๐Ÿš', '๐Ÿœ', '๐Ÿก', '๐Ÿณ', '๐Ÿž', '๐Ÿฉ', '๐Ÿฆ', '๐ŸŽ‚', '๐Ÿฐ', '๐Ÿช', '๐Ÿซ', '๐Ÿญ', '๐Ÿฏ', '๐ŸŽ', '๐Ÿ', '๐ŸŠ', '๐Ÿ‹', '๐Ÿ’', '๐Ÿ‡', '๐Ÿ‰', '๐Ÿ“', '๐Ÿ‘', '๐ŸŒ', '๐Ÿ', '๐Ÿ', '๐Ÿ†', '๐Ÿ…', '๐ŸŒฝ', '๐Ÿก', '๐Ÿฅ', '๐Ÿฆ', 'โ›ช', '๐Ÿฐ', 'โ›บ', '๐Ÿญ', '๐Ÿ—ป', '๐Ÿ—ฝ', '๐ŸŽ ', '๐ŸŽก', 'โ›ฒ', '๐ŸŽข', '๐Ÿšข', '๐Ÿšค', 'โš“', '๐Ÿš€', 'โœˆ', '๐Ÿš', '๐Ÿš‚', '๐Ÿš‹', '๐ŸšŽ', '๐ŸšŒ', '๐Ÿš™', '๐Ÿš—', '๐Ÿš•', '๐Ÿš›', '๐Ÿšจ', '๐Ÿš”', '๐Ÿš’', '๐Ÿš‘', '๐Ÿšฒ', '๐Ÿš ', '๐Ÿšœ', '๐Ÿšฆ', 'โš ', '๐Ÿšง', 'โ›ฝ', '๐ŸŽฐ', '๐Ÿ—ฟ', '๐ŸŽช', '๐ŸŽญ', '๐Ÿ‡ฏ๐Ÿ‡ต', '๐Ÿ‡ฐ๐Ÿ‡ท', '๐Ÿ‡ฉ๐Ÿ‡ช', '๐Ÿ‡จ๐Ÿ‡ณ', '๐Ÿ‡บ๐Ÿ‡ธ', '๐Ÿ‡ซ๐Ÿ‡ท', '๐Ÿ‡ช๐Ÿ‡ธ', '๐Ÿ‡ฎ๐Ÿ‡น', '๐Ÿ‡ท๐Ÿ‡บ', '๐Ÿ‡ฌ๐Ÿ‡ง', '1โƒฃ', '2โƒฃ', '3โƒฃ', '4โƒฃ', '5โƒฃ', '6โƒฃ', '7โƒฃ', '8โƒฃ', '9โƒฃ', '0โƒฃ', '๐Ÿ”Ÿ', 'โ—', 'โ“', 'โ™ฅ', 'โ™ฆ', '๐Ÿ’ฏ', '๐Ÿ”—', '๐Ÿ”ฑ', '๐Ÿ”ด', '๐Ÿ”ต', '๐Ÿ”ถ', '๐Ÿ”ท']; const EMOJIS = ['๐Ÿ˜‰', '๐Ÿ˜', '๐Ÿ˜›', '๐Ÿ˜ญ', '๐Ÿ˜ฑ', '๐Ÿ˜ก', '๐Ÿ˜Ž', '๐Ÿ˜ด', '๐Ÿ˜ต', '๐Ÿ˜ˆ', '๐Ÿ˜ฌ', '๐Ÿ˜‡', '๐Ÿ˜', '๐Ÿ‘ฎ', '๐Ÿ‘ท', '๐Ÿ’‚', '๐Ÿ‘ถ', '๐Ÿ‘จ', '๐Ÿ‘ฉ', '๐Ÿ‘ด', '๐Ÿ‘ต', '๐Ÿ˜ป', '๐Ÿ˜ฝ', '๐Ÿ™€', '๐Ÿ‘บ', '๐Ÿ™ˆ', '๐Ÿ™‰', '๐Ÿ™Š', '๐Ÿ’€', '๐Ÿ‘ฝ', '๐Ÿ’ฉ', '๐Ÿ”ฅ', '๐Ÿ’ฅ', '๐Ÿ’ค', '๐Ÿ‘‚', '๐Ÿ‘€', '๐Ÿ‘ƒ', '๐Ÿ‘…', '๐Ÿ‘„', '๐Ÿ‘', '๐Ÿ‘Ž', '๐Ÿ‘Œ', '๐Ÿ‘Š', 'โœŒ', 'โœ‹', '๐Ÿ‘', '๐Ÿ‘†', '๐Ÿ‘‡', '๐Ÿ‘‰', '๐Ÿ‘ˆ', '๐Ÿ™', '๐Ÿ‘', '๐Ÿ’ช', '๐Ÿšถ', '๐Ÿƒ', '๐Ÿ’ƒ', '๐Ÿ‘ซ', '๐Ÿ‘ช', '๐Ÿ‘ฌ', '๐Ÿ‘ญ', '๐Ÿ’…', '๐ŸŽฉ', '๐Ÿ‘‘', '๐Ÿ‘’', '๐Ÿ‘Ÿ', '๐Ÿ‘ž', '๐Ÿ‘ ', '๐Ÿ‘•', '๐Ÿ‘—', '๐Ÿ‘–', '๐Ÿ‘™', '๐Ÿ‘œ', '๐Ÿ‘“', '๐ŸŽ€', '๐Ÿ’„', '๐Ÿ’›', '๐Ÿ’™', '๐Ÿ’œ', '๐Ÿ’š', '๐Ÿ’', '๐Ÿ’Ž', '๐Ÿถ', '๐Ÿบ', '๐Ÿฑ', '๐Ÿญ', '๐Ÿน', '๐Ÿฐ', '๐Ÿธ', '๐Ÿฏ', '๐Ÿจ', '๐Ÿป', '๐Ÿท', '๐Ÿฎ', '๐Ÿ—', '๐Ÿด', '๐Ÿ‘', '๐Ÿ˜', '๐Ÿผ', '๐Ÿง', '๐Ÿฅ', '๐Ÿ”', '๐Ÿ', '๐Ÿข', '๐Ÿ›', '๐Ÿ', '๐Ÿœ', '๐Ÿž', '๐ŸŒ', '๐Ÿ™', '๐Ÿš', '๐ŸŸ', '๐Ÿฌ', '๐Ÿ‹', '๐Ÿ', '๐ŸŠ', '๐Ÿซ', '๐Ÿ€', '๐ŸŒน', '๐ŸŒป', '๐Ÿ', '๐ŸŒพ', '๐Ÿ„', '๐ŸŒต', '๐ŸŒด', '๐ŸŒณ', '๐ŸŒž', '๐ŸŒš', '๐ŸŒ™', '๐ŸŒŽ', '๐ŸŒ‹', 'โšก', 'โ˜”', 'โ„', 'โ›„', '๐ŸŒ€', '๐ŸŒˆ', '๐ŸŒŠ', '๐ŸŽ“', '๐ŸŽ†', '๐ŸŽƒ', '๐Ÿ‘ป', '๐ŸŽ…', '๐ŸŽ„', '๐ŸŽ', '๐ŸŽˆ', '๐Ÿ”ฎ', '๐ŸŽฅ', '๐Ÿ“ท', '๐Ÿ’ฟ', '๐Ÿ’ป', 'โ˜Ž', '๐Ÿ“ก', '๐Ÿ“บ', '๐Ÿ“ป', '๐Ÿ”‰', '๐Ÿ””', 'โณ', 'โฐ', 'โŒš', '๐Ÿ”’', '๐Ÿ”‘', '๐Ÿ”Ž', '๐Ÿ’ก', '๐Ÿ”ฆ', '๐Ÿ”Œ', '๐Ÿ”‹', '๐Ÿšฟ', '๐Ÿšฝ', '๐Ÿ”ง', '๐Ÿ”จ', '๐Ÿšช', '๐Ÿšฌ', '๐Ÿ’ฃ', '๐Ÿ”ซ', '๐Ÿ”ช', '๐Ÿ’Š', '๐Ÿ’‰', '๐Ÿ’ฐ', '๐Ÿ’ต', '๐Ÿ’ณ', 'โœ‰', '๐Ÿ“ซ', '๐Ÿ“ฆ', '๐Ÿ“…', '๐Ÿ“', 'โœ‚', '๐Ÿ“Œ', '๐Ÿ“Ž', 'โœ’', 'โœ', '๐Ÿ“', '๐Ÿ“š', '๐Ÿ”ฌ', '๐Ÿ”ญ', '๐ŸŽจ', '๐ŸŽฌ', '๐ŸŽค', '๐ŸŽง', '๐ŸŽต', '๐ŸŽน', '๐ŸŽป', '๐ŸŽบ', '๐ŸŽธ', '๐Ÿ‘พ', '๐ŸŽฎ', '๐Ÿƒ', '๐ŸŽฒ', '๐ŸŽฏ', '๐Ÿˆ', '๐Ÿ€', 'โšฝ', 'โšพ', '๐ŸŽพ', '๐ŸŽฑ', '๐Ÿ‰', '๐ŸŽณ', '๐Ÿ', '๐Ÿ‡', '๐Ÿ†', '๐ŸŠ', '๐Ÿ„', 'โ˜•', '๐Ÿผ', '๐Ÿบ', '๐Ÿท', '๐Ÿด', '๐Ÿ•', '๐Ÿ”', '๐ŸŸ', '๐Ÿ—', '๐Ÿฑ', '๐Ÿš', '๐Ÿœ', '๐Ÿก', '๐Ÿณ', '๐Ÿž', '๐Ÿฉ', '๐Ÿฆ', '๐ŸŽ‚', '๐Ÿฐ', '๐Ÿช', '๐Ÿซ', '๐Ÿญ', '๐Ÿฏ', '๐ŸŽ', '๐Ÿ', '๐ŸŠ', '๐Ÿ‹', '๐Ÿ’', '๐Ÿ‡', '๐Ÿ‰', '๐Ÿ“', '๐Ÿ‘', '๐ŸŒ', '๐Ÿ', '๐Ÿ', '๐Ÿ†', '๐Ÿ…', '๐ŸŒฝ', '๐Ÿก', '๐Ÿฅ', '๐Ÿฆ', 'โ›ช', '๐Ÿฐ', 'โ›บ', '๐Ÿญ', '๐Ÿ—ป', '๐Ÿ—ฝ', '๐ŸŽ ', '๐ŸŽก', 'โ›ฒ', '๐ŸŽข', '๐Ÿšข', '๐Ÿšค', 'โš“', '๐Ÿš€', 'โœˆ', '๐Ÿš', '๐Ÿš‚', '๐Ÿš‹', '๐ŸšŽ', '๐ŸšŒ', '๐Ÿš™', '๐Ÿš—', '๐Ÿš•', '๐Ÿš›', '๐Ÿšจ', '๐Ÿš”', '๐Ÿš’', '๐Ÿš‘', '๐Ÿšฒ', '๐Ÿš ', '๐Ÿšœ', '๐Ÿšฆ', 'โš ', '๐Ÿšง', 'โ›ฝ', '๐ŸŽฐ', '๐Ÿ—ฟ', '๐ŸŽช', '๐ŸŽญ', '๐Ÿ‡ฏ๐Ÿ‡ต', '๐Ÿ‡ฐ๐Ÿ‡ท', '๐Ÿ‡ฉ๐Ÿ‡ช', '๐Ÿ‡จ๐Ÿ‡ณ', '๐Ÿ‡บ๐Ÿ‡ธ', '๐Ÿ‡ซ๐Ÿ‡ท', '๐Ÿ‡ช๐Ÿ‡ธ', '๐Ÿ‡ฎ๐Ÿ‡น', '๐Ÿ‡ท๐Ÿ‡บ', '๐Ÿ‡ฌ๐Ÿ‡ง', '1โƒฃ', '2โƒฃ', '3โƒฃ', '4โƒฃ', '5โƒฃ', '6โƒฃ', '7โƒฃ', '8โƒฃ', '9โƒฃ', '0โƒฃ', '๐Ÿ”Ÿ', 'โ—', 'โ“', 'โ™ฅ', 'โ™ฆ', '๐Ÿ’ฏ', '๐Ÿ”—', '๐Ÿ”ฑ', '๐Ÿ”ด', '๐Ÿ”ต', '๐Ÿ”ถ', '๐Ÿ”ท'];
const TD_PARAMS_CONVERSION = [
'updateNewMessage' => [
'_' => 'updateNewMessage',
'disable_notification' => ['message', 'silent'],
'message' => ['message'],
],
'message' => [
'_' => 'message',
'id' => ['id'],
'sender_user_id' => ['from_id'],
'chat_id' => ['to_id', 'choose_chat_id_from_botapi'],
'send_state' => ['choose_incoming_or_sent'],
'can_be_edited' => ['choose_can_edit'],
'can_be_deleted' => ['choose_can_delete'],
'is_post' => ['post'],
'date' => ['date'],
'edit_date' => ['edit_date'],
'forward_info' => ['fwd_info', 'choose_forward_info'],
'reply_to_message_id' => ['reply_to_msg_id'],
'ttl' => ['choose_ttl'],
'ttl_expires_in' => ['choose_ttl_expires_in'],
'via_bot_user_id' => ['via_bot_id'],
'views' => ['views'],
'content' => ['choose_message_content'],
'reply_markup' => ['reply_markup'],
],
'messages.sendMessage' => [
'chat_id' => ['peer'],
'reply_to_message_id' => ['reply_to_msg_id'],
'disable_notification' => ['silent'],
'from_background' => ['background'],
'input_message_content' => ['choose_message_content'],
'reply_markup' => ['reply_markup'],
],
];
const TD_REVERSE = [
'sendMessage'=> 'messages.sendMessage',
];
const TD_IGNORE = ['updateMessageID'];
public $settings = []; public $settings = [];
private $config = ['expires' => -1]; private $config = ['expires' => -1];
@ -132,7 +174,7 @@ class MTProto extends \Volatile
private $msg_ids = []; private $msg_ids = [];
private $v = 0; private $v = 0;
private $dialog_params = ['_' => 'MadelineProto.DialogParams', 'limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty']]; private $dialog_params = ['_' => 'MadelineProto.dialogParams', 'limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty']];
private $zero; private $zero;
private $one; private $one;
private $two; private $two;
@ -246,6 +288,7 @@ class MTProto extends \Volatile
} }
unset($this->data); unset($this->data);
} }
if ($this->authorized === true) $this->authorized = self::LOGGED_IN;
$this->getting_state = false; $this->getting_state = false;
$this->reset_session(); $this->reset_session();
if (!isset($this->v) || $this->v !== $this->getV()) { if (!isset($this->v) || $this->v !== $this->getV()) {
@ -652,11 +695,395 @@ class MTProto extends \Volatile
public function getV() public function getV()
{ {
return 35; return 36;
} }
public function get_self() public function get_self()
{ {
return $this->authorization['user']; return $this->authorization['user'];
} }
const ALL_MIMES = [
'png' => [
0 => 'image/png',
1 => 'image/x-png',
],
'bmp' => [
0 => 'image/bmp',
1 => 'image/x-bmp',
2 => 'image/x-bitmap',
3 => 'image/x-xbitmap',
4 => 'image/x-win-bitmap',
5 => 'image/x-windows-bmp',
6 => 'image/ms-bmp',
7 => 'image/x-ms-bmp',
8 => 'application/bmp',
9 => 'application/x-bmp',
10 => 'application/x-win-bitmap',
],
'gif' => [
0 => 'image/gif',
],
'jpeg' => [
0 => 'image/jpeg',
1 => 'image/pjpeg',
],
'xspf' => [
0 => 'application/xspf+xml',
],
'vlc' => [
0 => 'application/videolan',
],
'wmv' => [
0 => 'video/x-ms-wmv',
1 => 'video/x-ms-asf',
],
'au' => [
0 => 'audio/x-au',
],
'ac3' => [
0 => 'audio/ac3',
],
'flac' => [
0 => 'audio/x-flac',
],
'ogg' => [
0 => 'audio/ogg',
1 => 'video/ogg',
2 => 'application/ogg',
],
'kmz' => [
0 => 'application/vnd.google-earth.kmz',
],
'kml' => [
0 => 'application/vnd.google-earth.kml+xml',
],
'rtx' => [
0 => 'text/richtext',
],
'rtf' => [
0 => 'text/rtf',
],
'jar' => [
0 => 'application/java-archive',
1 => 'application/x-java-application',
2 => 'application/x-jar',
],
'zip' => [
0 => 'application/x-zip',
1 => 'application/zip',
2 => 'application/x-zip-compressed',
3 => 'application/s-compressed',
4 => 'multipart/x-zip',
],
'7zip' => [
0 => 'application/x-compressed',
],
'xml' => [
0 => 'application/xml',
1 => 'text/xml',
],
'svg' => [
0 => 'image/svg+xml',
],
'3g2' => [
0 => 'video/3gpp2',
],
'3gp' => [
0 => 'video/3gp',
1 => 'video/3gpp',
],
'mp4' => [
0 => 'video/mp4',
],
'm4a' => [
0 => 'audio/x-m4a',
],
'f4v' => [
0 => 'video/x-f4v',
],
'flv' => [
0 => 'video/x-flv',
],
'webm' => [
0 => 'video/webm',
],
'aac' => [
0 => 'audio/x-acc',
],
'm4u' => [
0 => 'application/vnd.mpegurl',
],
'pdf' => [
0 => 'application/pdf',
1 => 'application/octet-stream',
],
'pptx' => [
0 => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
],
'ppt' => [
0 => 'application/powerpoint',
1 => 'application/vnd.ms-powerpoint',
2 => 'application/vnd.ms-office',
3 => 'application/msword',
],
'docx' => [
0 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
],
'xlsx' => [
0 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
1 => 'application/vnd.ms-excel',
],
'xl' => [
0 => 'application/excel',
],
'xls' => [
0 => 'application/msexcel',
1 => 'application/x-msexcel',
2 => 'application/x-ms-excel',
3 => 'application/x-excel',
4 => 'application/x-dos_ms_excel',
5 => 'application/xls',
6 => 'application/x-xls',
],
'xsl' => [
0 => 'text/xsl',
],
'mpeg' => [
0 => 'video/mpeg',
],
'mov' => [
0 => 'video/quicktime',
],
'avi' => [
0 => 'video/x-msvideo',
1 => 'video/msvideo',
2 => 'video/avi',
3 => 'application/x-troff-msvideo',
],
'movie' => [
0 => 'video/x-sgi-movie',
],
'log' => [
0 => 'text/x-log',
],
'txt' => [
0 => 'text/plain',
],
'css' => [
0 => 'text/css',
],
'html' => [
0 => 'text/html',
],
'wav' => [
0 => 'audio/x-wav',
1 => 'audio/wave',
2 => 'audio/wav',
],
'xhtml' => [
0 => 'application/xhtml+xml',
],
'tar' => [
0 => 'application/x-tar',
],
'tgz' => [
0 => 'application/x-gzip-compressed',
],
'psd' => [
0 => 'application/x-photoshop',
1 => 'image/vnd.adobe.photoshop',
],
'exe' => [
0 => 'application/x-msdownload',
],
'js' => [
0 => 'application/x-javascript',
],
'mp3' => [
0 => 'audio/mpeg',
1 => 'audio/mpg',
2 => 'audio/mpeg3',
3 => 'audio/mp3',
],
'rar' => [
0 => 'application/x-rar',
1 => 'application/rar',
2 => 'application/x-rar-compressed',
],
'gzip' => [
0 => 'application/x-gzip',
],
'hqx' => [
0 => 'application/mac-binhex40',
1 => 'application/mac-binhex',
2 => 'application/x-binhex40',
3 => 'application/x-mac-binhex40',
],
'cpt' => [
0 => 'application/mac-compactpro',
],
'bin' => [
0 => 'application/macbinary',
1 => 'application/mac-binary',
2 => 'application/x-binary',
3 => 'application/x-macbinary',
],
'oda' => [
0 => 'application/oda',
],
'ai' => [
0 => 'application/postscript',
],
'smil' => [
0 => 'application/smil',
],
'mif' => [
0 => 'application/vnd.mif',
],
'wbxml' => [
0 => 'application/wbxml',
],
'wmlc' => [
0 => 'application/wmlc',
],
'dcr' => [
0 => 'application/x-director',
],
'dvi' => [
0 => 'application/x-dvi',
],
'gtar' => [
0 => 'application/x-gtar',
],
'php' => [
0 => 'application/x-httpd-php',
1 => 'application/php',
2 => 'application/x-php',
3 => 'text/php',
4 => 'text/x-php',
5 => 'application/x-httpd-php-source',
],
'swf' => [
0 => 'application/x-shockwave-flash',
],
'sit' => [
0 => 'application/x-stuffit',
],
'z' => [
0 => 'application/x-compress',
],
'mid' => [
0 => 'audio/midi',
],
'aif' => [
0 => 'audio/x-aiff',
1 => 'audio/aiff',
],
'ram' => [
0 => 'audio/x-pn-realaudio',
],
'rpm' => [
0 => 'audio/x-pn-realaudio-plugin',
],
'ra' => [
0 => 'audio/x-realaudio',
],
'rv' => [
0 => 'video/vnd.rn-realvideo',
],
'jp2' => [
0 => 'image/jp2',
1 => 'video/mj2',
2 => 'image/jpx',
3 => 'image/jpm',
],
'tiff' => [
0 => 'image/tiff',
],
'eml' => [
0 => 'message/rfc822',
],
'pem' => [
0 => 'application/x-x509-user-cert',
1 => 'application/x-pem-file',
],
'p10' => [
0 => 'application/x-pkcs10',
1 => 'application/pkcs10',
],
'p12' => [
0 => 'application/x-pkcs12',
],
'p7a' => [
0 => 'application/x-pkcs7-signature',
],
'p7c' => [
0 => 'application/pkcs7-mime',
1 => 'application/x-pkcs7-mime',
],
'p7r' => [
0 => 'application/x-pkcs7-certreqresp',
],
'p7s' => [
0 => 'application/pkcs7-signature',
],
'crt' => [
0 => 'application/x-x509-ca-cert',
1 => 'application/pkix-cert',
],
'crl' => [
0 => 'application/pkix-crl',
1 => 'application/pkcs-crl',
],
'pgp' => [
0 => 'application/pgp',
],
'gpg' => [
0 => 'application/gpg-keys',
],
'rsa' => [
0 => 'application/x-pkcs7',
],
'ics' => [
0 => 'text/calendar',
],
'zsh' => [
0 => 'text/x-scriptzsh',
],
'cdr' => [
0 => 'application/cdr',
1 => 'application/coreldraw',
2 => 'application/x-cdr',
3 => 'application/x-coreldraw',
4 => 'image/cdr',
5 => 'image/x-cdr',
6 => 'zz-application/zz-winassoc-cdr',
],
'wma' => [
0 => 'audio/x-ms-wma',
],
'vcf' => [
0 => 'text/x-vcard',
],
'srt' => [
0 => 'text/srt',
],
'vtt' => [
0 => 'text/vtt',
],
'ico' => [
0 => 'image/x-icon',
1 => 'image/x-ico',
2 => 'image/vnd.microsoft.icon',
],
'csv' => [
0 => 'text/x-comma-separated-values',
1 => 'text/comma-separated-values',
2 => 'application/vnd.msexcel',
],
'json' => [
0 => 'application/json',
1 => 'text/json',
],
];
} }

View File

@ -48,6 +48,7 @@ trait ResponseHandler
foreach ($this->datacenter->sockets[$datacenter]->new_incoming as $current_msg_id) { foreach ($this->datacenter->sockets[$datacenter]->new_incoming as $current_msg_id) {
$unset = false; $unset = false;
\danog\MadelineProto\Logger::log(['Received '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].'.'], \danog\MadelineProto\Logger::ULTRA_VERBOSE); \danog\MadelineProto\Logger::log(['Received '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].'.'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
\danog\MadelineProto\Logger::log([$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
if (\danog\MadelineProto\Logger::$has_thread && is_object(\Thread::getCurrentThread())) { if (\danog\MadelineProto\Logger::$has_thread && is_object(\Thread::getCurrentThread())) {
if (!$this->synchronized(function ($zis, $datacenter, $current_msg_id) { if (!$this->synchronized(function ($zis, $datacenter, $current_msg_id) {
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['handling'])) { if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['handling'])) {

View File

@ -19,394 +19,10 @@ namespace danog\MadelineProto\TL\Conversion;
*/ */
trait Extension trait Extension
{ {
public $all_mimes = [
'png' => [
0 => 'image/png',
1 => 'image/x-png',
],
'bmp' => [
0 => 'image/bmp',
1 => 'image/x-bmp',
2 => 'image/x-bitmap',
3 => 'image/x-xbitmap',
4 => 'image/x-win-bitmap',
5 => 'image/x-windows-bmp',
6 => 'image/ms-bmp',
7 => 'image/x-ms-bmp',
8 => 'application/bmp',
9 => 'application/x-bmp',
10 => 'application/x-win-bitmap',
],
'gif' => [
0 => 'image/gif',
],
'jpeg' => [
0 => 'image/jpeg',
1 => 'image/pjpeg',
],
'xspf' => [
0 => 'application/xspf+xml',
],
'vlc' => [
0 => 'application/videolan',
],
'wmv' => [
0 => 'video/x-ms-wmv',
1 => 'video/x-ms-asf',
],
'au' => [
0 => 'audio/x-au',
],
'ac3' => [
0 => 'audio/ac3',
],
'flac' => [
0 => 'audio/x-flac',
],
'ogg' => [
0 => 'audio/ogg',
1 => 'video/ogg',
2 => 'application/ogg',
],
'kmz' => [
0 => 'application/vnd.google-earth.kmz',
],
'kml' => [
0 => 'application/vnd.google-earth.kml+xml',
],
'rtx' => [
0 => 'text/richtext',
],
'rtf' => [
0 => 'text/rtf',
],
'jar' => [
0 => 'application/java-archive',
1 => 'application/x-java-application',
2 => 'application/x-jar',
],
'zip' => [
0 => 'application/x-zip',
1 => 'application/zip',
2 => 'application/x-zip-compressed',
3 => 'application/s-compressed',
4 => 'multipart/x-zip',
],
'7zip' => [
0 => 'application/x-compressed',
],
'xml' => [
0 => 'application/xml',
1 => 'text/xml',
],
'svg' => [
0 => 'image/svg+xml',
],
'3g2' => [
0 => 'video/3gpp2',
],
'3gp' => [
0 => 'video/3gp',
1 => 'video/3gpp',
],
'mp4' => [
0 => 'video/mp4',
],
'm4a' => [
0 => 'audio/x-m4a',
],
'f4v' => [
0 => 'video/x-f4v',
],
'flv' => [
0 => 'video/x-flv',
],
'webm' => [
0 => 'video/webm',
],
'aac' => [
0 => 'audio/x-acc',
],
'm4u' => [
0 => 'application/vnd.mpegurl',
],
'pdf' => [
0 => 'application/pdf',
1 => 'application/octet-stream',
],
'pptx' => [
0 => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
],
'ppt' => [
0 => 'application/powerpoint',
1 => 'application/vnd.ms-powerpoint',
2 => 'application/vnd.ms-office',
3 => 'application/msword',
],
'docx' => [
0 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
],
'xlsx' => [
0 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
1 => 'application/vnd.ms-excel',
],
'xl' => [
0 => 'application/excel',
],
'xls' => [
0 => 'application/msexcel',
1 => 'application/x-msexcel',
2 => 'application/x-ms-excel',
3 => 'application/x-excel',
4 => 'application/x-dos_ms_excel',
5 => 'application/xls',
6 => 'application/x-xls',
],
'xsl' => [
0 => 'text/xsl',
],
'mpeg' => [
0 => 'video/mpeg',
],
'mov' => [
0 => 'video/quicktime',
],
'avi' => [
0 => 'video/x-msvideo',
1 => 'video/msvideo',
2 => 'video/avi',
3 => 'application/x-troff-msvideo',
],
'movie' => [
0 => 'video/x-sgi-movie',
],
'log' => [
0 => 'text/x-log',
],
'txt' => [
0 => 'text/plain',
],
'css' => [
0 => 'text/css',
],
'html' => [
0 => 'text/html',
],
'wav' => [
0 => 'audio/x-wav',
1 => 'audio/wave',
2 => 'audio/wav',
],
'xhtml' => [
0 => 'application/xhtml+xml',
],
'tar' => [
0 => 'application/x-tar',
],
'tgz' => [
0 => 'application/x-gzip-compressed',
],
'psd' => [
0 => 'application/x-photoshop',
1 => 'image/vnd.adobe.photoshop',
],
'exe' => [
0 => 'application/x-msdownload',
],
'js' => [
0 => 'application/x-javascript',
],
'mp3' => [
0 => 'audio/mpeg',
1 => 'audio/mpg',
2 => 'audio/mpeg3',
3 => 'audio/mp3',
],
'rar' => [
0 => 'application/x-rar',
1 => 'application/rar',
2 => 'application/x-rar-compressed',
],
'gzip' => [
0 => 'application/x-gzip',
],
'hqx' => [
0 => 'application/mac-binhex40',
1 => 'application/mac-binhex',
2 => 'application/x-binhex40',
3 => 'application/x-mac-binhex40',
],
'cpt' => [
0 => 'application/mac-compactpro',
],
'bin' => [
0 => 'application/macbinary',
1 => 'application/mac-binary',
2 => 'application/x-binary',
3 => 'application/x-macbinary',
],
'oda' => [
0 => 'application/oda',
],
'ai' => [
0 => 'application/postscript',
],
'smil' => [
0 => 'application/smil',
],
'mif' => [
0 => 'application/vnd.mif',
],
'wbxml' => [
0 => 'application/wbxml',
],
'wmlc' => [
0 => 'application/wmlc',
],
'dcr' => [
0 => 'application/x-director',
],
'dvi' => [
0 => 'application/x-dvi',
],
'gtar' => [
0 => 'application/x-gtar',
],
'php' => [
0 => 'application/x-httpd-php',
1 => 'application/php',
2 => 'application/x-php',
3 => 'text/php',
4 => 'text/x-php',
5 => 'application/x-httpd-php-source',
],
'swf' => [
0 => 'application/x-shockwave-flash',
],
'sit' => [
0 => 'application/x-stuffit',
],
'z' => [
0 => 'application/x-compress',
],
'mid' => [
0 => 'audio/midi',
],
'aif' => [
0 => 'audio/x-aiff',
1 => 'audio/aiff',
],
'ram' => [
0 => 'audio/x-pn-realaudio',
],
'rpm' => [
0 => 'audio/x-pn-realaudio-plugin',
],
'ra' => [
0 => 'audio/x-realaudio',
],
'rv' => [
0 => 'video/vnd.rn-realvideo',
],
'jp2' => [
0 => 'image/jp2',
1 => 'video/mj2',
2 => 'image/jpx',
3 => 'image/jpm',
],
'tiff' => [
0 => 'image/tiff',
],
'eml' => [
0 => 'message/rfc822',
],
'pem' => [
0 => 'application/x-x509-user-cert',
1 => 'application/x-pem-file',
],
'p10' => [
0 => 'application/x-pkcs10',
1 => 'application/pkcs10',
],
'p12' => [
0 => 'application/x-pkcs12',
],
'p7a' => [
0 => 'application/x-pkcs7-signature',
],
'p7c' => [
0 => 'application/pkcs7-mime',
1 => 'application/x-pkcs7-mime',
],
'p7r' => [
0 => 'application/x-pkcs7-certreqresp',
],
'p7s' => [
0 => 'application/pkcs7-signature',
],
'crt' => [
0 => 'application/x-x509-ca-cert',
1 => 'application/pkix-cert',
],
'crl' => [
0 => 'application/pkix-crl',
1 => 'application/pkcs-crl',
],
'pgp' => [
0 => 'application/pgp',
],
'gpg' => [
0 => 'application/gpg-keys',
],
'rsa' => [
0 => 'application/x-pkcs7',
],
'ics' => [
0 => 'text/calendar',
],
'zsh' => [
0 => 'text/x-scriptzsh',
],
'cdr' => [
0 => 'application/cdr',
1 => 'application/coreldraw',
2 => 'application/x-cdr',
3 => 'application/x-coreldraw',
4 => 'image/cdr',
5 => 'image/x-cdr',
6 => 'zz-application/zz-winassoc-cdr',
],
'wma' => [
0 => 'audio/x-ms-wma',
],
'vcf' => [
0 => 'text/x-vcard',
],
'srt' => [
0 => 'text/srt',
],
'vtt' => [
0 => 'text/vtt',
],
'ico' => [
0 => 'image/x-icon',
1 => 'image/x-ico',
2 => 'image/vnd.microsoft.icon',
],
'csv' => [
0 => 'text/x-comma-separated-values',
1 => 'text/comma-separated-values',
2 => 'application/vnd.msexcel',
],
'json' => [
0 => 'application/json',
1 => 'text/json',
],
];
public function get_extension_from_mime($mime) public function get_extension_from_mime($mime)
{ {
foreach ($this->all_mimes as $key => $value) { foreach (self::ALL_MIMES as $key => $value) {
if (array_search($mime, (array) $value) !== false) { if (array_search($mime, (array) $value) !== false) {
return '.'.$key; return '.'.$key;
} }

View File

@ -14,48 +14,6 @@ namespace danog\MadelineProto\TL\Conversion;
trait TD trait TD
{ {
protected $td_params_conversion = [
'updateNewMessage' => [
'_' => 'updateNewMessage',
'disable_notification' => ['message', 'silent'],
'message' => ['message'],
],
'message' => [
'_' => 'message',
'id' => ['id'],
'sender_user_id' => ['from_id'],
'chat_id' => ['to_id', 'choose_chat_id_from_botapi'],
'send_state' => ['choose_incoming_or_sent'],
'can_be_edited' => ['choose_can_edit'],
'can_be_deleted' => ['choose_can_delete'],
'is_post' => ['post'],
'date' => ['date'],
'edit_date' => ['edit_date'],
'forward_info' => ['fwd_info', 'choose_forward_info'],
'reply_to_message_id' => ['reply_to_msg_id'],
'ttl' => ['choose_ttl'],
'ttl_expires_in' => ['choose_ttl_expires_in'],
'via_bot_user_id' => ['via_bot_id'],
'views' => ['views'],
'content' => ['choose_message_content'],
'reply_markup' => ['reply_markup'],
],
'messages.sendMessage' => [
'chat_id' => ['peer'],
'reply_to_message_id' => ['reply_to_msg_id'],
'disable_notification' => ['silent'],
'from_background' => ['background'],
'input_message_content' => ['choose_message_content'],
'reply_markup' => ['reply_markup'],
],
];
protected $reverse = [
'sendMessage'=> 'messages.sendMessage',
];
protected $ignore = ['updateMessageID'];
public function tdcli_to_td(&$params, $key = null) public function tdcli_to_td(&$params, $key = null)
{ {
if (!$this->is_array($params)) { if (!$this->is_array($params)) {
@ -81,9 +39,9 @@ trait TD
public function td_to_mtproto($params) public function td_to_mtproto($params)
{ {
$newparams = ['_' => $this->reverse[$params['_']]]; $newparams = ['_' => self::REVERSE[$params['_']]];
foreach ($this->td_params_conversion[$newparams['_']] as $td => $mtproto) { foreach (self::TD_PARAMS_CONVERSION[$newparams['_']] as $td => $mtproto) {
if ($this->is_array($mtproto)) { if ($this->is_array($mtproto)) {
switch (end($mtproto)) { switch (end($mtproto)) {
case 'choose_message_content': case 'choose_message_content':
@ -126,10 +84,10 @@ trait TD
return $params; return $params;
} }
$newparams = ['_' => $params['_']]; $newparams = ['_' => $params['_']];
if ($this->in_array($params['_'], $this->ignore)) { if ($this->in_array($params['_'], self::TD_IGNORE)) {
return $params; return $params;
} }
foreach ($this->td_params_conversion[$params['_']] as $td => $mtproto) { foreach (self::TD_PARAMS_CONVERSION[$params['_']] as $td => $mtproto) {
if (is_string($mtproto)) { if (is_string($mtproto)) {
$newparams[$td] = $mtproto; $newparams[$td] = $mtproto;
} else { } else {

View File

@ -235,7 +235,7 @@ trait TL
return $tl_elem['predicate'] === 'boolTrue'; return $tl_elem['predicate'] === 'boolTrue';
} }
public function serialize_object($type, $object, $layer = '') public function serialize_object($type, $object, $layer = -1)
{ {
switch ($type['type']) { switch ($type['type']) {
case 'int': case 'int':
@ -390,7 +390,7 @@ trait TL
return $tl['id'].$this->serialize_params($tl, $arguments); return $tl['id'].$this->serialize_params($tl, $arguments);
} }
public function serialize_params($tl, $arguments, $layer = '') public function serialize_params($tl, $arguments, $layer = -1)
{ {
$serialized = ''; $serialized = '';

View File

@ -22,76 +22,74 @@ class TLConstructor extends \Volatile
public $predicate = []; public $predicate = [];
public $type = []; public $type = [];
public $params = []; public $params = [];
public $layers = []; public $layer = [];
public $key = 0;
public function __sleep() public function __sleep()
{ {
return ['id', 'predicate', 'type', 'params', 'layers']; return ['id', 'predicate', 'type', 'params', 'layer', 'key'];
} }
public function add($json_dict, $scheme_type) public function add($json_dict, $scheme_type)
{ {
$json_dict['id'] = 'a'.$json_dict['id']; $this->id[$this->key] = $json_dict['id'];
$json_dict['predicate'] = (string) ((($scheme_type === 'mtproto' && $json_dict['predicate'] === 'message') ? 'MT' : '').$json_dict['predicate']); $this->predicate[$this->key] = (string) ((($scheme_type === 'mtproto' && $json_dict['predicate'] === 'message') ? 'MT' : '').$json_dict['predicate']);
$json_dict['predicate'] .= $scheme_type === 'secret' ? $json_dict['layer'] : ''; $this->type[$this->key] = (($scheme_type === 'mtproto' && $json_dict['type'] === 'Message') ? 'MT' : '').$json_dict['type'];
$this->id[$json_dict['predicate']] = $json_dict['id']; $this->params[$this->key] = $json_dict['params'];
$this->predicate[$json_dict['id']] = $json_dict['predicate'];
$this->type[$json_dict['id']] = (($scheme_type === 'mtproto' && $json_dict['type'] === 'Message') ? 'MT' : '').$json_dict['type'];
$this->params[$json_dict['id']] = $json_dict['params'];
$this->parse_params($json_dict['id'], $scheme_type === 'mtproto');
if ($scheme_type === 'secret') { if ($scheme_type === 'secret') {
$this->layers[$json_dict['layer']] = $json_dict['layer']; $this->layer[$this->key] = $json_dict['layer'];
} }
$this->parse_params($this->key, $scheme_type === 'mtproto');
$this->key++;
} }
public function find_by_type($type) public function find_by_type($type)
{ {
$id = array_search($type, (array) $this->type, true); $key = array_search($type, (array) $this->type, true);
return ($id === false) ? false : [ return ($key === false) ? false : [
'id' => substr($id, 1), 'id' => $this->id[$key],
'predicate' => $this->predicate[$id], 'predicate' => $this->predicate[$key],
'type' => $this->type[$id], 'type' => $this->type[$key],
'params' => $this->array_cast_recursive($this->params[$id]), 'params' => $this->array_cast_recursive($this->params[$key]),
]; ];
} }
public function find_by_predicate($predicate, $layer = '') public function find_by_predicate($predicate, $layer = -1)
{ {
if ($layer !== '' && !isset($this->id[$predicate.$layer])) { if ($layer !== -1) {
foreach ($this->layers as $newlayer) { $newlayer = -1;
if (isset($this->id[$predicate.$newlayer]) || $newlayer > $layer) { $keys = array_keys((array) $this->predicate, $predicate);
break; foreach ($keys as $k) {
if ($this->layer[$k] <= $layer && $this->layer[$k] > $newlayer) {
$key = $k;
$newlayer = $this->layer[$k];
}
if (!isset($key)) {
$key = $keys[0];
} }
$nlayer = $newlayer;
} }
$layer = $nlayer; } else {
$key = array_search($predicate, (array) $this->predicate, true);
} }
if (!isset($this->id[$predicate.$layer])) {
return false;
}
$id = $this->id[$predicate.$layer];
return [ return ($key === false) ? false : [
'id' => substr($id, 1), 'id' => $this->id[$key],
'predicate' => $this->predicate[$id], 'predicate' => $this->predicate[$key],
'type' => $this->type[$id], 'type' => $this->type[$key],
'params' => $this->array_cast_recursive($this->params[$id]), 'params' => $this->array_cast_recursive($this->params[$key]),
]; ];
} }
public function find_by_id($oid) public function find_by_id($id)
{ {
$id = 'a'.$oid; $key = array_search($id, (array) $this->id, true);
if (!isset($this->predicate[$id])) {
return false;
}
return [ return ($key === false) ? false : [
'id' => $oid, 'id' => $this->id[$key],
'predicate' => $this->predicate[$id], 'predicate' => $this->predicate[$key],
'type' => $this->type[$id], 'type' => $this->type[$key],
'params' => $this->array_cast_recursive($this->params[$id]), 'params' => $this->array_cast_recursive($this->params[$key]),
]; ];
} }
} }

View File

@ -22,54 +22,49 @@ class TLMethod extends \Volatile
public $type = []; public $type = [];
public $params = []; public $params = [];
public $method_namespace = []; public $method_namespace = [];
public $key = 0;
public function __sleep() public function __sleep()
{ {
return ['id', 'method', 'type', 'params', 'method_namespace']; return ['id', 'method', 'type', 'params', 'method_namespace', 'key'];
} }
public function add($json_dict) public function add($json_dict)
{ {
$json_dict['id'] = 'a'.$json_dict['id']; $this->id[$this->key] = $json_dict['id'];
$this->id[$json_dict['method']] = $json_dict['id']; $this->method[$this->key] = $json_dict['method'];
$this->method[$json_dict['id']] = $json_dict['method']; $this->type[$this->key] = $json_dict['type'];
$this->type[$json_dict['id']] = $json_dict['type']; $this->params[$this->key] = $json_dict['params'];
$this->params[$json_dict['id']] = $json_dict['params'];
$namespace = explode('.', $json_dict['method']); $namespace = explode('.', $json_dict['method']);
if (isset($namespace[1])) { if (isset($namespace[1])) {
$this->method_namespace[$namespace[1]] = $namespace[0]; $this->method_namespace[$namespace[1]] = $namespace[0];
} }
$this->parse_params($json_dict['id']); $this->parse_params($this->key);
$this->key++;
} }
public function find_by_method($method) public function find_by_method($method)
{ {
if (!isset($this->id[$method])) { $key = array_search($method, (array) $this->method, true);
return false;
}
$id = $this->id[$method];
return [ return ($key === false) ? false : [
'id' => substr($id, 1), 'id' => $this->id[$key],
'method' => $this->method[$id], 'method' => $this->method[$key],
'type' => $this->type[$id], 'type' => $this->type[$key],
'params' => $this->array_cast_recursive($this->params[$id]), 'params' => $this->array_cast_recursive($this->params[$key]),
]; ];
} }
public function find_by_id($oid) public function find_by_id($id)
{ {
$id = 'a'.$oid; $key = array_search($id, (array) $this->id, true);
if (!isset($this->method[$id])) {
return false;
}
return [ return ($key === false) ? false : [
'id' => $oid, 'id' => $this->id[$key],
'method' => $this->method[$id], 'method' => $this->method[$key],
'type' => $this->type[$id], 'type' => $this->type[$key],
'params' => $this->array_cast_recursive($this->params[$id]), 'params' => $this->array_cast_recursive($this->params[$key]),
]; ];
} }
} }