Multipart
in package
Encodes a Bot API payload as `multipart/form-data`, which is the only way to upload a file.
Telegram takes uploads two ways, and this class emits both from the same
payload: a top-level file field (photo, document, thumbnail, ...) is sent
as a form part under its own name, while a file nested inside an object - the
media of an InputMedia, a sticker in createNewStickerSet - is replaced by
an attach://<name> reference and sent as a part under that generated name.
Tags
Table of Contents
Properties
- $boundary : string
- $parts : array<int, array{name: string, contents: string, filename: ?string, contentType: ?string}>
Methods
- __toString() : string
- The encoded body.
- containsFile() : bool
- True when the payload holds a file anywhere, at any depth.
- encode() : self
- Builds the body for a payload that contains at least one {@see InputFile}.
- getBoundary() : string
- getContentType() : string
- The `Content-Type` header this body must be sent with.
- __construct() : mixed
- addField() : void
- addFile() : void
- extract() : mixed
- Walks a nested value, swapping every {@see InputFile} for an `attach://` reference and registering the bytes as a part.
- stringify() : string
- Scalars go over the wire the way Telegram expects to read them back.
Properties
$boundary read-only
private
string
$boundary
$parts
private
array<int, array{name: string, contents: string, filename: ?string, contentType: ?string}>
$parts
= []
Methods
__toString()
The encoded body.
public
__toString() : string
Return values
stringcontainsFile()
True when the payload holds a file anywhere, at any depth.
public
static containsFile(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolencode()
Builds the body for a payload that contains at least one {@see InputFile}.
public
static encode(array<string, mixed> $content[, ?string $boundary = null ]) : self
Parameters
- $content : array<string, mixed>
- $boundary : ?string = null
Return values
selfgetBoundary()
public
getBoundary() : string
Return values
stringgetContentType()
The `Content-Type` header this body must be sent with.
public
getContentType() : string
Return values
string__construct()
private
__construct(string $boundary) : mixed
Parameters
- $boundary : string
addField()
private
addField(string $name, string $value) : void
Parameters
- $name : string
- $value : string
addFile()
private
addFile(string $name, InputFile $file) : void
Parameters
- $name : string
- $file : InputFile
extract()
Walks a nested value, swapping every {@see InputFile} for an `attach://` reference and registering the bytes as a part.
private
extract(mixed $value, int &$attachments) : mixed
Parameters
- $value : mixed
- $attachments : int
stringify()
Scalars go over the wire the way Telegram expects to read them back.
private
static stringify(mixed $value) : string
Parameters
- $value : mixed