diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 298c24c6..de5ea867 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -371,8 +371,8 @@ class API extends InternalDoc } catch (\Throwable $e) { $errors = [\time() => $errors[\time()] ?? 0]; $errors[\time()]++; - if ($errors[\time()] > 100 && (!$this->inited() || !$started)) { - $this->logger->logger("More than 100 errors in a second and not inited, exiting!", Logger::FATAL_ERROR); + if ($errors[\time()] > 10 && (!$this->inited() || !$started)) { + $this->logger->logger("More than 10 errors in a second and not inited, exiting!", Logger::FATAL_ERROR); return; } echo $e; diff --git a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php index 5bca7562..99151d03 100644 --- a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php @@ -34,7 +34,7 @@ use danog\MadelineProto\Tools; class WriteLoop extends ResumableSignalLoop { const MAX_COUNT = 1020; - const MAX_SIZE = 1 << 15; + private const MAX_SIZE = 1 << 15; const MAX_IDS = 8192; use Common; diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 78dc420e..85d70c60 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -99,7 +99,7 @@ class MTProto extends AsyncConstruct implements TLCallback */ const V = 147; /** - * String release version. + * Release version. * * @var string */ @@ -137,12 +137,16 @@ class MTProto extends AsyncConstruct implements TLCallback /** * Bad message error codes. * + * @internal + * * @var array */ const BAD_MSG_ERROR_CODES = [16 => 'msg_id too low (most likely, client time is wrong; it would be worthwhile to synchronize it using msg_id notifications and re-send the original message with the “correct” msg_id or wrap it in a container with a new msg_id if the original message had waited too long on the client to be transmitted)', 17 => 'msg_id too high (similar to the previous case, the client time has to be synchronized, and the message re-sent with the correct msg_id)', 18 => 'incorrect two lower order msg_id bits (the server expects client message msg_id to be divisible by 4)', 19 => 'container msg_id is the same as msg_id of a previously received message (this must never happen)', 20 => 'message too old, and it cannot be verified whether the server has received a message with this msg_id or not', 32 => 'msg_seqno too low (the server has already received a message with a lower msg_id but with either a higher or an equal and odd seqno)', 33 => 'msg_seqno too high (similarly, there is a message with a higher msg_id but with either a lower or an equal and odd seqno)', 34 => 'an even msg_seqno expected (irrelevant message), but odd received', 35 => 'odd msg_seqno expected (relevant message), but even received', 48 => 'incorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it)', 64 => 'invalid container']; /** * Localized message info flags. * + * @internal + * * @var array */ const MSGS_INFO_FLAGS = [1 => 'nothing is known about the message (msg_id too low, the other party may have forgotten it)', 2 => 'message not received (msg_id falls within the range of stored identifiers; however, the other party has certainly not received a message like that)', 3 => 'message not received (msg_id too high; however, the other party has certainly not received it yet)', 4 => 'message received (note that this response is also at the same time a receipt acknowledgment)', 8 => ' and message already acknowledged', 16 => ' and message not requiring acknowledgment', 32 => ' and RPC query contained in message being processed or processing already complete', 64 => ' and content-related response to message already generated', 128 => ' and other party knows for a fact that message is already received']; @@ -164,44 +168,29 @@ class MTProto extends AsyncConstruct implements TLCallback * @var int */ const SECRET_READY = 2; + /** + * @internal + */ const GETUPDATES_HANDLER = 'getUpdates'; + /** + * @internal + */ const TD_PARAMS_CONVERSION = ['updateNewMessage' => ['_' => 'updateNewMessage', 'disable_notification' => ['message', 'silent'], 'message' => ['message']], 'message' => ['_' => 'message', 'id' => ['id'], 'sender_user_id' => ['from_id'], 'chat_id' => ['peer_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']]]; + /** + * @internal + */ const TD_REVERSE = ['sendMessage' => 'messages.sendMessage']; + /** + * @internal + */ const TD_IGNORE = ['updateMessageID']; + /** + * @internal + */ const BOTAPI_PARAMS_CONVERSION = ['disable_web_page_preview' => 'no_webpage', 'disable_notification' => 'silent', 'reply_to_message_id' => 'reply_to_msg_id', 'chat_id' => 'peer', 'text' => 'message']; - // Not content related constructors - const NOT_CONTENT_RELATED = [ - //'rpc_result', - //'rpc_error', - 'rpc_drop_answer', - 'rpc_answer_unknown', - 'rpc_answer_dropped_running', - 'rpc_answer_dropped', - 'get_future_salts', - 'future_salt', - 'future_salts', - 'ping', - 'pong', - 'ping_delay_disconnect', - 'destroy_session', - 'destroy_session_ok', - 'destroy_session_none', - //'new_session_created', - 'msg_container', - 'msg_copy', - 'gzip_packed', - 'http_wait', - 'msgs_ack', - 'bad_msg_notification', - 'bad_server_salt', - 'msgs_state_req', - 'msgs_state_info', - 'msgs_all_info', - 'msg_detailed_info', - 'msg_new_detailed_info', - 'msg_resend_req', - 'msg_resend_ans_req', - ]; + /** + * @internal + */ const DEFAULT_GETUPDATES_PARAMS = ['offset' => 0, 'limit' => null, 'timeout' => 100]; /** * Array of references to all instances of MTProto. diff --git a/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php b/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php index f79baf16..0a8e3cc7 100644 --- a/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php @@ -369,7 +369,7 @@ trait ResponseHandler $this->logger->logger('If you intentionally deleted this account, ignore this message.', \danog\MadelineProto\Logger::FATAL_ERROR); } $this->API->resetSession(); - \danog\MadelineProto\Tools::callFork((function () use (&$request, &$response): \Generator { + \danog\MadelineProto\Tools::callFork((function () use ($request, &$response): \Generator { yield from $this->API->initAuthorization(); $this->handleReject($request, new \danog\MadelineProto\RPCErrorException($response['error_message'], $response['error_code'], $request['_'] ?? '')); })()); @@ -378,7 +378,7 @@ trait ResponseHandler case 'AUTH_KEY_INVALID': if ($this->API->authorized !== MTProto::LOGGED_IN) { $this->gotResponseForOutgoingMessageId($request_id); - \danog\MadelineProto\Tools::callFork((function () use (&$request, &$response): \Generator { + \danog\MadelineProto\Tools::callFork((function () use ($request, &$response): \Generator { yield from $this->API->initAuthorization(); $this->handleReject($request, new \danog\MadelineProto\RPCErrorException($response['error_message'], $response['error_code'], $request['_'] ?? '')); })()); @@ -403,7 +403,7 @@ trait ResponseHandler $this->logger->logger('Then login again.', \danog\MadelineProto\Logger::FATAL_ERROR); $this->logger->logger('If you intentionally deleted this account, ignore this message.', \danog\MadelineProto\Logger::FATAL_ERROR); $this->API->resetSession(); - \danog\MadelineProto\Tools::callFork((function () use (&$request, &$response): \Generator { + \danog\MadelineProto\Tools::callFork((function () use ($request, &$response): \Generator { yield from $this->API->initAuthorization(); $this->handleReject($request, new \danog\MadelineProto\RPCErrorException($response['error_message'], $response['error_code'], $request['_'] ?? '')); })()); diff --git a/src/danog/MadelineProto/MTProtoSession/SeqNoHandler.php b/src/danog/MadelineProto/MTProtoSession/SeqNoHandler.php index a3cd2bd5..f929160c 100644 --- a/src/danog/MadelineProto/MTProtoSession/SeqNoHandler.php +++ b/src/danog/MadelineProto/MTProtoSession/SeqNoHandler.php @@ -19,8 +19,6 @@ namespace danog\MadelineProto\MTProtoSession; -use danog\MadelineProto\MTProto; - /** * Manages sequence number. */ @@ -55,6 +53,37 @@ trait SeqNoHandler public function contentRelated($method): bool { $method = \is_array($method) && isset($method['_']) ? $method['_'] : $method; - return \is_string($method) ? !\in_array($method, MTProto::NOT_CONTENT_RELATED) : true; + return \is_string($method) ? !\in_array($method, [ + //'rpc_result', + //'rpc_error', + 'rpc_drop_answer', + 'rpc_answer_unknown', + 'rpc_answer_dropped_running', + 'rpc_answer_dropped', + 'get_future_salts', + 'future_salt', + 'future_salts', + 'ping', + 'pong', + 'ping_delay_disconnect', + 'destroy_session', + 'destroy_session_ok', + 'destroy_session_none', + //'new_session_created', + 'msg_container', + 'msg_copy', + 'gzip_packed', + 'http_wait', + 'msgs_ack', + 'bad_msg_notification', + 'bad_server_salt', + 'msgs_state_req', + 'msgs_state_info', + 'msgs_all_info', + 'msg_detailed_info', + 'msg_new_detailed_info', + 'msg_resend_req', + 'msg_resend_ans_req', + ]) : true; } } diff --git a/src/danog/MadelineProto/MyTelegramOrgWrapper.php b/src/danog/MadelineProto/MyTelegramOrgWrapper.php index 05ee3ba1..7426d3aa 100644 --- a/src/danog/MadelineProto/MyTelegramOrgWrapper.php +++ b/src/danog/MadelineProto/MyTelegramOrgWrapper.php @@ -68,7 +68,7 @@ class MyTelegramOrgWrapper /** * Endpoint. */ - const MY_TELEGRAM_URL = 'https://my.telegram.org'; + private const MY_TELEGRAM_URL = 'https://my.telegram.org'; /** * Sleep function. * diff --git a/src/danog/MadelineProto/PhpDocBuilder.php b/src/danog/MadelineProto/PhpDocBuilder.php index 37148f5a..5034ade4 100644 --- a/src/danog/MadelineProto/PhpDocBuilder.php +++ b/src/danog/MadelineProto/PhpDocBuilder.php @@ -28,6 +28,7 @@ use danog\MadelineProto\MTProtoTools\PasswordCalculator; use danog\MadelineProto\MTProtoTools\ReferenceDatabase; use danog\MadelineProto\MTProtoTools\UpdatesState; use danog\MadelineProto\TL\TL; +use danog\MadelineProto\TL\TLCallback; use danog\MadelineProto\TL\TLConstructors; use danog\MadelineProto\TL\TLMethods; use danog\MadelineProto\TON\ADNLConnection; @@ -44,63 +45,70 @@ use phpDocumentor\Reflection\DocBlock\Tags\See; use phpDocumentor\Reflection\DocBlockFactory; use ReflectionClass; use ReflectionClassConstant; +use ReflectionMethod; class PhpDocBuilder { + private const DISALLOW = [ + AnnotationsBuilder::class, + APIFactory::class, + APIWrapper::class, + AbstractAPIFactory::class, + Bug74586Exception::class, + Connection::class, + ContextConnector::class, + DataCenter::class, + DataCenterConnection::class, + DoHConnector::class, + DocsBuilder::class, + InternalDoc::class, + Lang::class, + LightState::class, + Magic::class, + PhpDocBuilder::class, + RSA::class, + Serialization::class, + SessionPaths::class, + SettingsEmpty::class, + SettingsAbstract::class, + Snitch::class, + AsyncConstruct::class, + Server::class, // Remove when done + VoIP::class, + + Crypt::class, + NothingInTheSocketException::class, + + GarbageCollector::class, + MinDatabase::class, + PasswordCalculator::class, + ReferenceDatabase::class, + UpdatesState::class, + + TL::class, + TLConstructors::class, + TLMethods::class, + TLCallback::class, + + ADNLConnection::class, + TAPIFactory::class, + TInternalDoc::class, + Lite::class, + + \ArrayIterator::class, + ]; private DocBlockFactory $factory; - public function __construct() + private string $output; + public function __construct(string $output) { $this->factory = DocBlockFactory::createInstance(); + $this->output = $output; } public function run() { $classes = ClassFinder::getClassesInNamespace('danog\\MadelineProto', ClassFinder::RECURSIVE_MODE); foreach ($classes as $class) { - if (\in_array($class, [ - AnnotationsBuilder::class, - APIFactory::class, - APIWrapper::class, - AbstractAPIFactory::class, - Bug74586Exception::class, - Connection::class, - ContextConnector::class, - DataCenter::class, - DataCenterConnection::class, - DoHConnector::class, - DocsBuilder::class, - InternalDoc::class, - Lang::class, - LightState::class, - Magic::class, - PhpDocBuilder::class, - RSA::class, - Serialization::class, - SessionPaths::class, - SettingsEmpty::class, - SettingsAbstract::class, - Snitch::class, - AsyncConstruct::class, - Server::class, // Remove when done - VoIP::class, - - Crypt::class, - NothingInTheSocketException::class, - - GarbageCollector::class, - MinDatabase::class, - PasswordCalculator::class, - ReferenceDatabase::class, - UpdatesState::class, - - TL::class, - TLConstructors::class, - TLMethods::class, - - ADNLConnection::class, - TAPIFactory::class, - TInternalDoc::class, - Lite::class, - ]) || str_starts_with($class, 'danog\\MadelineProto\\Ipc') + if (\in_array($class, self::DISALLOW) || str_starts_with($class, 'danog\\MadelineProto\\Ipc') || str_starts_with($class, 'danog\\MadelineProto\\Loop\\Update') || str_starts_with($class, 'danog\\MadelineProto\\Loop\\Connection') || str_starts_with($class, 'danog\\MadelineProto\\MTProto\\') @@ -117,9 +125,29 @@ class PhpDocBuilder $this->generate(new ReflectionClass(DbPropertiesTrait::class)); } + /** + * Create directory recursively. + * + * @param string $file + * @return string + */ + private static function createDir(string $file): string + { + $dir = \dirname($file); + if (!\file_exists($dir)) { + $this->createDir($dir); + } + return $file; + } + private function generate(ReflectionClass $class): void { $name = $class->getName(); + $fName = $this->output; + $fName .= \str_replace(['\\', 'danog\\MadelineProto'], ['/', ''], $name); + $fName .= '.md'; + $handle = \fopen(self::createDir($fName), 'w+'); + $doc = $class->getDocComment(); if (!$doc) { throw new Exception("$name has no PHPDOC!"); @@ -163,15 +191,48 @@ class PhpDocBuilder } } + fwrite($handle, "---\n"); + fwrite($handle, "title: $name: $title\n"); + fwrite($handle, "description: $description\n"); + fwrite($handle, "image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png\n"); + fwrite($handle, "---\n"); + fwrite($handle, "# $name: $title\n"); + fwrite($handle, "[Back to API index](index.md)\n\n"); + + fwrite($handle, "> Author: $author \n"); + $constants = []; foreach ($class->getConstants() as $key => $value) { $refl = new ReflectionClassConstant($name, $key); - $doc = $this->factory->create($refl->getDocComment() ?? ''); + if (!$refl->isPublic()) { + continue; + } + $description = ''; + if ($refl->getDocComment()) { + $docConst = $this->factory->create($refl->getDocComment()); + if (\in_array($refl->getDeclaringClass()->getName(), self::DISALLOW)) { + continue; + } + $description .= $docConst->getSummary(); + if ($docConst->getDescription()) { + $description .= "\n\n"; + $description .= $docConst->getDescription(); + } + if ($docConst->getTagsByName('internal')) { + continue; + } + } + $description = \trim($description); $constants[$key] = [ $value, - $description, - $doc->getDescription() + $description ]; } + + $methods = []; + foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { + } + + } } diff --git a/src/danog/MadelineProto/Settings/Logger.php b/src/danog/MadelineProto/Settings/Logger.php index e010dea1..70a5528d 100644 --- a/src/danog/MadelineProto/Settings/Logger.php +++ b/src/danog/MadelineProto/Settings/Logger.php @@ -169,6 +169,10 @@ class Logger extends SettingsAbstract */ public function setExtra($extra): self { + if ($this->type === MadelineProtoLogger::CALLABLE_LOGGER && !is_callable($extra)) { + $this->setType(MadelineProtoLogger::NO_LOGGER); + return $this; + } $this->extra = $extra; return $this; diff --git a/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php b/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php index 6d8d869d..e34be47f 100644 --- a/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php +++ b/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php @@ -37,7 +37,7 @@ use danog\MadelineProto\Stream\RawStreamInterface; class BufferedRawStream implements BufferedStreamInterface, BufferInterface, RawStreamInterface { use RawStream; - const MAX_SIZE = 10 * 1024 * 1024; + private const MAX_SIZE = 10 * 1024 * 1024; protected $stream; protected $memory_stream; private $append = ''; diff --git a/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php b/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php index dba835e7..401d7583 100644 --- a/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php +++ b/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php @@ -35,7 +35,7 @@ use danog\MadelineProto\Stream\RawStreamInterface; */ class SocksProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface { - const REPS = [0 => 'succeeded', 1 => 'general SOCKS server failure', 2 => 'connection not allowed by ruleset', 3 => 'Network unreachable', 4 => 'Host unreachable', 5 => 'Connection refused', 6 => 'TTL expired', 7 => 'Command not supported', 8 => 'Address type not supported']; + private const REPS = [0 => 'succeeded', 1 => 'general SOCKS server failure', 2 => 'connection not allowed by ruleset', 3 => 'Network unreachable', 4 => 'Host unreachable', 5 => 'Connection refused', 6 => 'TTL expired', 7 => 'Command not supported', 8 => 'Address type not supported']; use RawStream; /** * Stream. diff --git a/src/danog/MadelineProto/TL/Conversion/Extension.php b/src/danog/MadelineProto/TL/Conversion/Extension.php index 8d2c00ac..b24693de 100644 --- a/src/danog/MadelineProto/TL/Conversion/Extension.php +++ b/src/danog/MadelineProto/TL/Conversion/Extension.php @@ -19,7 +19,7 @@ namespace danog\MadelineProto\TL\Conversion; */ abstract class Extension { - const ALL_MIMES = ['webp' => [0 => 'image/webp'], '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']]; + private const ALL_MIMES = ['webp' => [0 => 'image/webp'], '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']]; /** * Get mime type from file extension. * diff --git a/src/danog/MadelineProto/TL/TLCallback.php b/src/danog/MadelineProto/TL/TLCallback.php index 2446f786..3619c760 100644 --- a/src/danog/MadelineProto/TL/TLCallback.php +++ b/src/danog/MadelineProto/TL/TLCallback.php @@ -25,18 +25,50 @@ namespace danog\MadelineProto\TL; interface TLCallback { /** - * + * Called after serializing a method + * + * @internal * * @var int */ const METHOD_CALLBACK = 0; + /** + * Called before serializing a method + * + * @internal + * + * @var int + */ const METHOD_BEFORE_CALLBACK = 1; + /** + * Called after serializing a constructor + * + * @internal + * + * @var int + */ const CONSTRUCTOR_CALLBACK = 2; + /** + * Called before serializing a constructor + * + * @internal + * + * @var int + */ const CONSTRUCTOR_BEFORE_CALLBACK = 3; + /** + * Called on constructor serialization + * + * @internal + * + * @var int + */ const CONSTRUCTOR_SERIALIZE_CALLBACK = 4; /** * Called if objects of the specified type cannot be serialized. * + * @internal + * * @var int */ const TYPE_MISMATCH_CALLBACK = 5;