danog\MadelineProto\Tools
Author: Daniil Gentili daniil@daniil.it
Some tools.
Constants
danog\MadelineProto\Tools::ALL_MIMES:
Method list:
testFibers(int $fiberCount = 100000): array{maxFibers: int, realMemoryMb: int, maps: ?int, maxMaps: ?int}getMaps(): ?intgetMaxMaps(): ?intstringToStream(string $str): \Amp\ByteStream\ReadableBuffergenVectorHash(array<(string|int)> $longs): stringrandomInt(integer $modulus = 0): intrandom(integer $length): stringposmod(int $a, int $b): intunpackSignedInt(string $value): intunpackSignedLong(string $value): intunpackSignedLongString((string|int|array) $value): stringpackSignedInt(integer $value): stringpackSignedLong(int $value): stringpackUnsignedInt(int $value): stringpackDouble(float $value): stringunpackDouble(string $value): floatisArrayOrAlike(mixed $var): boolarr(mixed ...$params): arraybase64urlDecode(string $data): stringbase64urlEncode(string $data): stringrleDecode(string $string): stringrleEncode(string $string): stringinflateStripped(string $stripped): stringcloseConnection(string $message): voidend(array<T> $what): TisAltervista(): boolopenFileAppendOnly(string $path): \Amp\File\FilegetStreamPipe(): \Amp\ByteStream\PipeopenBuffered(\danog\MadelineProto\LocalFile|\danog\MadelineProto\RemoteUrl|\Amp\ByteStream\ReadableStream $stream, ?\Amp\Cancellation $cancellation = NULL): Closure(int): ?stringvalidateEventHandlerClass(class-string<\danog\MadelineProto\EventHandler> $class): list<\danog\MadelineProto\EventHandlerIssue>canConvertOgg(): boolcanUseFFmpeg(?\Amp\Cancellation $cancellation = NULL): boolrethrow(\Throwable $e): voidcallFork(\Generator|\Amp\Future|callable $callable, mixed ...$args): \Amp\Future<T>flock(string $file, integer $operation, float $polling = 0.1, ?\Amp\Cancellation $token = NULL, ?\Closure $failureCb = NULL): ($token is null ? Closure(): void : (Closure(): void | null))sleep(float $time): voidreadLine(string $prompt = '', ?\Amp\Cancellation $cancel = NULL): stringecho(string $string): voidmbStrlen(string $text): intmbSubstr(string $text, integer $offset, (null|int) $length = NULL): stringmbStrSplit(string $text, integer $length): array<string>htmlToMessageEntities(string $html): \danog\MadelineProto\TextEntitiesmarkdownToMessageEntities(string $markdown): \danog\MadelineProto\TextEntitiesentitiesToHtml(string $message, list<(\danog\MadelineProto\EventHandler\Message\Entities\MessageEntity|array{_: string, offset: int, length: int})> $entities, bool $allowTelegramTags = false): stringtoCamelCase(string $input): stringtoSnakeCase(string $input): stringhtmlEscape(string $what): stringmarkdownEscape(string $what): stringmarkdownCodeblockEscape(string $what): stringmarkdownCodeEscape(string $what): stringmarkdownUrlEscape(string $what): stringgetMimeFromExtension(string $extension, string $default): stringgetExtensionFromMime(string $mime): stringgetExtensionFromLocation(mixed $location, string $default): stringgetMimeFromFile(string $file): stringgetMimeFromBuffer(string $buffer): string
Methods:
testFibers(int $fiberCount = 100000): array{maxFibers: int, realMemoryMb: int, maps: ?int, maxMaps: ?int}
Test fibers.
Parameters:
$fiberCount:int
getMaps(): ?int
Get current number of memory-mapped regions, UNIX only.
getMaxMaps(): ?int
Get maximum number of memory-mapped regions, UNIX only. Use testFibers to get the maximum number of fibers on any platform.
stringToStream(string $str): \Amp\ByteStream\ReadableBuffer
Converts a string into an async amphp stream.
Parameters:
$str:string
See also:
\Amp\ByteStream\ReadableBuffer
genVectorHash(array<(string|int)> $longs): string
Generate MTProto vector hash.
Returns a vector hash.
Parameters:
$longs:array<(string|int)>IDs
randomInt(integer $modulus = 0): int
Get random integer.
Parameters:
$modulus:integerModulus
random(integer $length): string
Get secure random string of specified length.
Parameters:
$length:integerLength
posmod(int $a, int $b): int
Positive modulo Works just like the % (modulus) operator, only returns always a postive number.
Parameters:
$a:intA$b:intB
unpackSignedInt(string $value): int
Unpack base256 signed int.
Parameters:
$value:stringbase256 int
unpackSignedLong(string $value): int
Unpack base256 signed long.
Parameters:
$value:stringbase256 long
unpackSignedLongString((string|int|array) $value): string
Unpack base256 signed long to string.
Parameters:
$value:(string|int|array)base256 long
packSignedInt(integer $value): string
Convert integer to base256 signed int.
Parameters:
$value:integerValue to convert
packSignedLong(int $value): string
Convert integer to base256 long.
Parameters:
$value:intValue to convert
packUnsignedInt(int $value): string
Convert value to unsigned base256 int.
Parameters:
$value:intValue
packDouble(float $value): string
Convert double to binary version.
Parameters:
$value:floatValue to convert
unpackDouble(string $value): float
Unpack binary double.
Parameters:
$value:stringValue to unpack
isArrayOrAlike(mixed $var): bool
Check if is array or similar (traversable && countable && arrayAccess).
Parameters:
$var:mixedValue to check
arr(mixed ...$params): array
Create array.
Parameters:
...$params:mixedParams
base64urlDecode(string $data): string
base64URL decode.
Parameters:
$data:stringData to decode
base64urlEncode(string $data): string
Base64URL encode.
Parameters:
$data:stringData to encode
rleDecode(string $string): string
null-byte RLE decode.
Parameters:
$string:stringData to decode
rleEncode(string $string): string
null-byte RLE encode.
Parameters:
$string:stringData to encode
inflateStripped(string $stripped): string
Inflate stripped photosize to full JPG payload.
Parameters:
$stripped:stringStripped photosize
closeConnection(string $message): void
Close connection with client, connected via web.
Parameters:
$message:stringMessage
end(array<T> $what): T
Get final element of array.
Parameters:
$what:array<T>Array
isAltervista(): bool
Whether this is altervista.
openFileAppendOnly(string $path): \Amp\File\File
Opens a file in append-only mode.
Parameters:
$path:stringFile path.
See also:
\Amp\File\File
getStreamPipe(): \Amp\ByteStream\Pipe
Obtains a pipe that can be used to upload a file from a stream.
See also:
\Amp\ByteStream\Pipe
openBuffered(\danog\MadelineProto\LocalFile|\danog\MadelineProto\RemoteUrl|\Amp\ByteStream\ReadableStream $stream, ?\Amp\Cancellation $cancellation = NULL): Closure(int): ?string
Provide a buffered reader for a file, URL or amp stream.
Parameters:
$stream:\danog\MadelineProto\LocalFile|\danog\MadelineProto\RemoteUrl|\Amp\ByteStream\ReadableStream$cancellation:?\Amp\Cancellation
See also:
\danog\MadelineProto\LocalFile: Indicates a local file to upload.\danog\MadelineProto\RemoteUrl: Indicates a remote URL to upload.\Amp\ByteStream\ReadableStream\Amp\Cancellation
validateEventHandlerClass(class-string<\danog\MadelineProto\EventHandler> $class): list<\danog\MadelineProto\EventHandlerIssue>
Perform static analysis on a certain event handler class, to make sure it satisfies some performance requirements.
Parameters:
$class:class-string<\danog\MadelineProto\EventHandler>Class name
See also:
\danog\MadelineProto\EventHandler: Event handler.\danog\MadelineProto\EventHandlerIssue: Represents an event handler issue.
canConvertOgg(): bool
Whether we can convert any audio/video file to a VoIP OGG OPUS file, or the files must be preconverted using @libtgvoipbot.
canUseFFmpeg(?\Amp\Cancellation $cancellation = NULL): bool
Whether we can convert any audio/video file using ffmpeg.
Parameters:
$cancellation:?\Amp\Cancellation
See also:
\Amp\Cancellation
rethrow(\Throwable $e): void
Rethrow exception into event loop.
Parameters:
$e:\Throwable
See also:
\Throwable
callFork(\Generator|\Amp\Future|callable $callable, mixed ...$args): \Amp\Future<T>
Fork a new green thread and execute the passed function in the background.
Parameters:
$callable:\Generator|\Amp\Future|callable...$args:mixedArguments forwarded to the function when forking the thread.
See also:
\Generator\Amp\Future
flock(string $file, integer $operation, float $polling = 0.1, ?\Amp\Cancellation $token = NULL, ?\Closure $failureCb = NULL): ($token is null ? Closure(): void : (Closure(): void | null))
Asynchronously lock a file Resolves with a callbable that MUST eventually be called in order to release the lock.
Parameters:
$file:stringFile to lock$operation:integerLocking mode$polling:floatPolling interval$token:?\Amp\CancellationCancellation token$failureCb:?\ClosureFailure callback, called only once if the first locking attempt fails.
See also:
\Amp\Cancellation\Closure
sleep(float $time): void
Asynchronously sleep.
Parameters:
$time:floatNumber of seconds to sleep for
readLine(string $prompt = '', ?\Amp\Cancellation $cancel = NULL): string
Asynchronously read line.
Parameters:
$prompt:stringPrompt$cancel:?\Amp\Cancellation
See also:
\Amp\Cancellation
echo(string $string): void
Asynchronously write to stdout/browser.
Parameters:
$string:stringMessage to echo
mbStrlen(string $text): int
Get Telegram UTF-8 length of string.
Parameters:
$text:stringText
mbSubstr(string $text, integer $offset, (null|int) $length = NULL): string
Telegram UTF-8 multibyte substring.
Parameters:
$text:stringText to substring$offset:integerOffset$length:(null|int)Length
mbStrSplit(string $text, integer $length): array<string>
Telegram UTF-8 multibyte split.
Parameters:
$text:stringText$length:integerLength
htmlToMessageEntities(string $html): \danog\MadelineProto\TextEntities
Manually convert HTML to a message and a set of entities.
NOTE: You don’t have to use this method to send HTML messages.
This method is already called automatically by using parse_mode: “HTML” in messages.sendMessage, messages.sendMedia, et cetera…
Parameters:
$html:string
Return value: Object containing message and entities
See also:
- https://docs.madelineproto.xyz/API_docs/methods/messages.sendMessage.html#usage-of-parse_mode
\danog\MadelineProto\TextEntities: Class that converts HTML or markdown to a message + set of entities.
markdownToMessageEntities(string $markdown): \danog\MadelineProto\TextEntities
Manually convert markdown to a message and a set of entities.
NOTE: You don’t have to use this method to send Markdown messages.
This method is already called automatically by using parse_mode: “Markdown” in messages.sendMessage, messages.sendMedia, et cetera…
Parameters:
$markdown:string
Return value: Object containing message and entities
See also:
- https://docs.madelineproto.xyz/API_docs/methods/messages.sendMessage.html#usage-of-parse_mode
\danog\MadelineProto\TextEntities: Class that converts HTML or markdown to a message + set of entities.
entitiesToHtml(string $message, list<(\danog\MadelineProto\EventHandler\Message\Entities\MessageEntity|array{_: string, offset: int, length: int})> $entities, bool $allowTelegramTags = false): string
Convert a message and a set of entities to HTML.
Parameters:
$message:string$entities:list<(\danog\MadelineProto\EventHandler\Message\Entities\MessageEntity|array{_: string, offset: int, length: int})>$allowTelegramTags:boolWhether to allow telegram-specific tags like tg-spoiler, tg-emoji, mention links and so on…
See also:
\danog\MadelineProto\EventHandler\Message\Entities\MessageEntity: Master class for message entities.
toCamelCase(string $input): string
Convert to camelCase.
Parameters:
$input:stringString
toSnakeCase(string $input): string
Convert to snake_case.
Parameters:
$input:stringString
htmlEscape(string $what): string
Escape string for MadelineProto’s HTML entity converter.
Parameters:
$what:stringString to escape
markdownEscape(string $what): string
Escape string for markdown.
Parameters:
$what:stringString to escape
markdownCodeblockEscape(string $what): string
Escape string for markdown codeblock.
Parameters:
$what:stringString to escape
markdownCodeEscape(string $what): string
Escape string for markdown code section.
Parameters:
$what:stringString to escape
markdownUrlEscape(string $what): string
Escape string for URL.
Parameters:
$what:stringString to escape
getMimeFromExtension(string $extension, string $default): string
Get mime type from file extension.
Parameters:
$extension:stringFile extension$default:stringDefault mime type
getExtensionFromMime(string $mime): string
Get extension from mime type.
Parameters:
$mime:stringMIME type
getExtensionFromLocation(mixed $location, string $default): string
Get extension from file location.
Parameters:
$location:mixedFile location$default:stringDefault extension
getMimeFromFile(string $file): string
Get mime type of file.
Parameters:
$file:stringFile
getMimeFromBuffer(string $buffer): string
Get mime type from buffer.
Parameters:
$buffer:stringBuffer
Generated by danog/phpdoc