MadelineProtoDocs/docs/PHP/danog/MadelineProto/TON/API.md

993 lines
18 KiB
Markdown

---
title: danog\MadelineProto\TON\API: TON API.
description:
---
# `danog\MadelineProto\TON\API`
[Back to index](../../../index.md)
> Author: Daniil Gentili <daniil@daniil.it>
TON API.
## Method list:
* `after(\Generator|\Promise $a, \Generator|\Promise $b): \Amp\Promise`
* `all((\Generator|\Promise)[] $promises): \Amp\Promise`
* `any((\Promise|\Generator)[] $promises): \Amp\Promise`
* `arr(mixed $params): array`
* `base64urlDecode(string $data): string`
* `base64urlEncode(string $data): string`
* `botAPItoMTProto(array $parameters): \Amp\Promise`
* `call(\Generator|\Promise|mixed $promise): \Amp\Promise`
* `callFork(\Generator|\Promise $promise, ?\Generator|\Promise $actual, string $file): \Amp\Promise|mixed`
* `callForkDefer(\Generator|\Promise $promise): void`
* `connect(string $config): \Amp\Promise`
* `echo(string $string): \Amp\Promise`
* `end(array $what): mixed`
* `first((\Promise|\Generator)[] $promises): \Amp\Promise`
* `flock(string $file, int $operation, float $polling, ?\Promise $token, ?callable $failureCb): \Amp\Promise<?callable>`
* `genVectorHash(array $ints): \int Vector hash`
* `getExtensionFromLocation(mixed $location, string $default): string`
* `getExtensionFromMime(string $mime): string`
* `getMethodNamespaces(): mixed`
* `getMimeFromBuffer(string $buffer): string`
* `getMimeFromExtension(string $extension, string $default): string`
* `getMimeFromFile(string $file): string`
* `getVar(object $obj, string $var): mixed`
* `hasVar(object $obj, string $var): bool`
* `inflateStripped(string $stripped): \string JPG payload`
* `isAltervista(): bool`
* `isArrayOrAlike(mixed $var): bool`
* `logger(string $param, int $level, string $file): mixed`
* `loop(callable $func): \Amp\Promise`
* `markdownEscape(string $hwat): string`
* `methodCall(string $methodName, array $args): \Amp\Promise`
* `methodEscape(string $method): string`
* `packDouble(float $value): string`
* `packSignedInt(int $value): string`
* `packSignedLong(int $value): string`
* `packUnsignedInt(int $value): string`
* `posmod(int $a, int $b): \int Modulo`
* `random(int $length): \string Random string`
* `randomInt(int $modulus): int`
* `readLine(string $prompt): \Amp\Promise<string>`
* `rethrow(\Throwable $e, string $file): void`
* `rleDecode(string $string): string`
* `rleEncode(string $string): string`
* `setVar(object $obj, string $var, mixed $val): void`
* `sleep(int|float $time): \Amp\Promise`
* `some((\Promise|\Generator)[] $promises): \Amp\Promise`
* `timeout(\Generator|\Promise $promise, int $timeout): \Amp\Promise`
* `timeoutWithDefault(\Promise|\Generator $promise, int $timeout, mixed $default): \Amp\Promise<\TReturn>|\Promise<\TReturnAlt>`
* `toCamelCase(string $input): string`
* `toSnakeCase(string $input): string`
* `typeEscape(string $type): string`
* `unpackDouble(string $value): float`
* `unpackSignedInt(string $value): int`
* `unpackSignedLong(string $value): int`
* `unpackSignedLongString(string $value): string`
* `wait(\Generator|\Promise $promise, bool $ignoreSignal): mixed`
* `async(bool $async): void`
* `init(): void`
* `initAsynchronously(): \Generator`
* `inited(): bool`
* `forceInit(bool $inited): void`
## Methods:
### `after(\Generator|\Promise $a, \Generator|\Promise $b): \Amp\Promise`
Call promise $b after promise $a.
Parameters:
* `$a`: `\Generator|\Promise` Promise A
* `$b`: `\Generator|\Promise` Promise B
#### See also:
* `\Generator`
* `\Promise`
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `all((\Generator|\Promise)[] $promises): \Amp\Promise`
Returns a promise that succeeds when all promises succeed, and fails if any promise fails.
Returned promise succeeds with an array of values used to succeed each contained promise, with keys corresponding to the array of promises.
Parameters:
* `$promises`: `(\Generator|\Promise)[]` Promises
#### See also:
* `\Generator`
* `\Promise`
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `any((\Promise|\Generator)[] $promises): \Amp\Promise`
Returns a promise that is resolved when all promises are resolved. The returned promise will not fail.
Parameters:
* `$promises`: `(\Promise|\Generator)[]` Promises
#### See also:
* `\Promise`
* `\Generator`
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `arr(mixed $params): array`
Create array.
Parameters:
* `$params`: `mixed` Params
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `base64urlDecode(string $data): string`
base64URL decode.
Parameters:
* `$data`: `string` Data to decode
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `base64urlEncode(string $data): string`
Base64URL encode.
Parameters:
* `$data`: `string` Data to encode
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `botAPItoMTProto(array $parameters): \Amp\Promise`
Convert parameters.
Parameters:
* `$parameters`: `array` Parameters
#### See also:
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `call(\Generator|\Promise|mixed $promise): \Amp\Promise`
Convert generator, promise or any other value to a promise.
Parameters:
* `$promise`: `\Generator|\Promise|mixed`
Full type:
```
\Generator<mixed, mixed, mixed, \TReturn>|\Promise<\TReturn>|\TReturn
```
Fully typed return value:
```
\Promise<\TReturn>
```
#### See also:
* `\Generator`
* `\Promise`
* `\TReturn`
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `callFork(\Generator|\Promise $promise, ?\Generator|\Promise $actual, string $file): \Amp\Promise|mixed`
Call promise in background.
Parameters:
* `$promise`: `\Generator|\Promise` Promise to resolve
* `$actual`: `?\Generator|\Promise` Promise to resolve instead of $promise
* `$file`: `string` File
#### See also:
* `\Generator`
* `\Promise`
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `callForkDefer(\Generator|\Promise $promise): void`
Call promise in background, deferring execution.
Parameters:
* `$promise`: `\Generator|\Promise` Promise to resolve
#### See also:
* `\Generator`
* `\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `connect(string $config): \Amp\Promise`
Connect to the lite endpoints specified in the config file.
Parameters:
* `$config`: `string` Path to config file
#### See also:
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `echo(string $string): \Amp\Promise`
Asynchronously write to stdout/browser.
Parameters:
* `$string`: `string` Message to echo
#### See also:
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `end(array $what): mixed`
Get final element of array.
Parameters:
* `$what`: `array` Array
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `first((\Promise|\Generator)[] $promises): \Amp\Promise`
Returns a promise that succeeds when the first promise succeeds, and fails only if all promises fail.
Parameters:
* `$promises`: `(\Promise|\Generator)[]` Promises
#### See also:
* `\Promise`
* `\Generator`
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `flock(string $file, int $operation, float $polling, ?\Promise $token, ?callable $failureCb): \Amp\Promise<?callable>`
Asynchronously lock a file
Resolves with a callbable that MUST eventually be called in order to release the lock.
Parameters:
* `$file`: `string` File to lock
* `$operation`: `int` Locking mode
* `$polling`: `float` Polling interval
* `$token`: `?\Promise` Cancellation token
* `$failureCb`: `?callable` Failure callback, called only once if the first locking attempt fails.
#### See also:
* `\Promise`
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `genVectorHash(array $ints): \int Vector hash`
Generate MTProto vector hash.
Parameters:
* `$ints`: `array` IDs
Return value: Vector hash
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `getExtensionFromLocation(mixed $location, string $default): string`
Get extension from file location.
Parameters:
* `$location`: `mixed` File location
* `$default`: `string` Default extension
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `getExtensionFromMime(string $mime): string`
Get extension from mime type.
Parameters:
* `$mime`: `string` MIME type
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `getMethodNamespaces(): mixed`
Get TL method namespaces.
Fully typed return value:
```
array|\Amp\Promise<array>
```
#### See also:
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `getMimeFromBuffer(string $buffer): string`
Get mime type from buffer.
Parameters:
* `$buffer`: `string` Buffer
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `getMimeFromExtension(string $extension, string $default): string`
Get mime type from file extension.
Parameters:
* `$extension`: `string` File extension
* `$default`: `string` Default mime type
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `getMimeFromFile(string $file): string`
Get mime type of file.
Parameters:
* `$file`: `string` File
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `getVar(object $obj, string $var): mixed`
Accesses a private variable from an object.
Parameters:
* `$obj`: `object` Object
* `$var`: `string` Attribute name
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `hasVar(object $obj, string $var): bool`
Checks private property exists in an object.
Parameters:
* `$obj`: `object` Object
* `$var`: `string` Attribute name
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `inflateStripped(string $stripped): \string JPG payload`
Inflate stripped photosize to full JPG payload.
Parameters:
* `$stripped`: `string` Stripped photosize
Return value: JPG payload
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `isAltervista(): bool`
Whether this is altervista.
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `isArrayOrAlike(mixed $var): bool`
Check if is array or similar (traversable && countable && arrayAccess).
Parameters:
* `$var`: `mixed` Value to check
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `logger(string $param, int $level, string $file): mixed`
Logger.
Parameters:
* `$param`: `string` Parameter
* `$level`: `int` Logging level
* `$file`: `string` File where the message originated
Fully typed return value:
```
void|\Amp\Promise<void>
```
#### See also:
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `loop(callable $func): \Amp\Promise`
Asynchronously run async callable.
Parameters:
* `$func`: `callable` Function
#### See also:
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `markdownEscape(string $hwat): string`
Escape string for markdown.
Parameters:
* `$hwat`: `string` String to escape
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `methodCall(string $methodName, array $args): \Amp\Promise`
Call lite method.
Parameters:
* `$methodName`: `string` Method name
* `$args`: `array` Arguments
#### See also:
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `methodEscape(string $method): string`
Escape method name.
Parameters:
* `$method`: `string` Method name
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `packDouble(float $value): string`
Convert double to binary version.
Parameters:
* `$value`: `float` Value to convert
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `packSignedInt(int $value): string`
Convert integer to base256 signed int.
Parameters:
* `$value`: `int` Value to convert
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `packSignedLong(int $value): string`
Convert integer to base256 long.
Parameters:
* `$value`: `int` Value to convert
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `packUnsignedInt(int $value): string`
Convert value to unsigned base256 int.
Parameters:
* `$value`: `int` Value
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `posmod(int $a, int $b): \int Modulo`
Positive modulo
Works just like the % (modulus) operator, only returns always a postive number.
Parameters:
* `$a`: `int` A
* `$b`: `int` B
Return value: Modulo
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `random(int $length): \string Random string`
Get random string of specified length.
Parameters:
* `$length`: `int` Length
Return value: Random string
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `randomInt(int $modulus): int`
Get random integer.
Parameters:
* `$modulus`: `int` Modulus
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `readLine(string $prompt): \Amp\Promise<string>`
Asynchronously read line.
Parameters:
* `$prompt`: `string` Prompt
#### See also:
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `rethrow(\Throwable $e, string $file): void`
Rethrow error catched in strand.
Parameters:
* `$e`: `\Throwable` Exception
* `$file`: `string` File where the strand started
#### See also:
* `\Throwable`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `rleDecode(string $string): string`
null-byte RLE decode.
Parameters:
* `$string`: `string` Data to decode
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `rleEncode(string $string): string`
null-byte RLE encode.
Parameters:
* `$string`: `string` Data to encode
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `setVar(object $obj, string $var, mixed $val): void`
Sets a private variable in an object.
Parameters:
* `$obj`: `object` Object
* `$var`: `string` Attribute name
* `$val`: `mixed` Attribute value
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `sleep(int|float $time): \Amp\Promise`
Asynchronously sleep.
Parameters:
* `$time`: `int|float` Number of seconds to sleep for
#### See also:
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `some((\Promise|\Generator)[] $promises): \Amp\Promise`
Resolves with a two-item array delineating successful and failed Promise results.
The returned promise will only fail if the given number of required promises fail.
Parameters:
* `$promises`: `(\Promise|\Generator)[]` Promises
#### See also:
* `\Promise`
* `\Generator`
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `timeout(\Generator|\Promise $promise, int $timeout): \Amp\Promise`
Create an artificial timeout for any \Generator or Promise.
Parameters:
* `$promise`: `\Generator|\Promise`
* `$timeout`: `int`
#### See also:
* `\Generator`
* `\Promise`
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `timeoutWithDefault(\Promise|\Generator $promise, int $timeout, mixed $default): \Amp\Promise<\TReturn>|\Promise<\TReturnAlt>`
Creates an artificial timeout for any `Promise`.
If the promise is resolved before the timeout expires, the result is returned
If the timeout expires before the promise is resolved, a default value is returned
Parameters:
* `$promise`: `\Promise|\Generator` Promise to which the timeout is applied.
Full type:
```
\Promise<\TReturn>|\TGenerator
```
* `$timeout`: `int` Timeout in milliseconds.
* `$default`: `mixed`
Full type:
```
\TReturnAlt
```
#### See also:
* `\Promise`
* `\Generator`
* `\TReturn`
* `\TGenerator`
* `\TReturnAlt`
* `\Amp\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `toCamelCase(string $input): string`
Convert to camelCase.
Parameters:
* `$input`: `string` String
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `toSnakeCase(string $input): string`
Convert to snake_case.
Parameters:
* `$input`: `string` String
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `typeEscape(string $type): string`
Escape type name.
Parameters:
* `$type`: `string` String to escape
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `unpackDouble(string $value): float`
Unpack binary double.
Parameters:
* `$value`: `string` Value to unpack
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `unpackSignedInt(string $value): int`
Unpack base256 signed int.
Parameters:
* `$value`: `string` base256 int
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `unpackSignedLong(string $value): int`
Unpack base256 signed long.
Parameters:
* `$value`: `string` base256 long
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `unpackSignedLongString(string $value): string`
Unpack base256 signed long to string.
Parameters:
* `$value`: `string` base256 long
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `wait(\Generator|\Promise $promise, bool $ignoreSignal): mixed`
Synchronously wait for a promise|generator.
Parameters:
* `$promise`: `\Generator|\Promise` The promise to wait for
* `$ignoreSignal`: `bool` Whether to ignore shutdown signals
#### See also:
* `\Generator`
* `\Promise`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `async(bool $async): void`
Enable or disable async.
Parameters:
* `$async`: `bool` Whether to enable or disable async
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `init(): void`
Blockingly init.
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `initAsynchronously(): \Generator`
Asynchronously init.
#### See also:
* `\Generator`
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `inited(): bool`
Check if we've already inited.
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
### `forceInit(bool $inited): void`
Mark instance as (de)inited forcefully.
Parameters:
* `$inited`: `bool` Whether to mark the instance as inited or deinited
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)