phpbotgram

Serializer
in package

FinalYes

Walks a TelegramObject/TelegramMethod into a snake_case-keyed array (dump) and back (load). Bot threading + InputFile detachment + JSON encoding all live in BaseSession::prepareValue.

Table of Contents

Properties

$camelToSnakeCache  : array<string, string>

Methods

dump()  : array<string, mixed>
Dumps to snake_case keys. Skips Unspecified values; preserves nulls (BaseSession::prepareValue strips them downstream per the null-filter rule).
load()  : T
Loads a TelegramObject from a snake_case dict, recursively binding $bot.
camelToSnake()  : string
dumpValue()  : mixed
isPhpdocRichTextUnion()  : bool
isRichTextUnion()  : bool
loadArrayValue()  : array<string|int, mixed>
loadPhpdocValue()  : mixed
loadRichTextValue()  : mixed
loadTelegramObjectValue()  : TelegramObject
loadValue()  : mixed
phpdocClassName()  : null|TelegramObject>
phpdocScalarMatches()  : bool
phpdocTypeForParam()  : string|null
splitPhpdocUnion()  : array<int, string>
stripPhpdocNull()  : string
toStringKeyedArray()  : array<string, mixed>
Narrows an array with unknown key type to string-keyed for PHPStan.

Properties

$camelToSnakeCache

private static array<string, string> $camelToSnakeCache = []

Methods

dump()

Dumps to snake_case keys. Skips Unspecified values; preserves nulls (BaseSession::prepareValue strips them downstream per the null-filter rule).

public static dump(BotContextController $object) : array<string, mixed>

Accepts any BotContextController (TelegramObject or TelegramMethod) so that AmphpSession can serialise method parameters without a separate code path.

Per-class WireNames const overrides the default camelToSnake mapping: public const array WireNames = ['fromUser' => 'from']; lets the property $fromUser serialize as wire key from.

Parameters
$object : BotContextController
Return values
array<string, mixed>

load()

Loads a TelegramObject from a snake_case dict, recursively binding $bot.

public static load(T> $class, array<string, mixed> $data[, Bot|null $bot = null ]) : T
Parameters
$class : T>
$data : array<string, mixed>
$bot : Bot|null = null
Tags
template
Return values
T

camelToSnake()

private static camelToSnake(string $camel) : string
Parameters
$camel : string
Return values
string

dumpValue()

private static dumpValue(mixed $value) : mixed
Parameters
$value : mixed

isPhpdocRichTextUnion()

private static isPhpdocRichTextUnion(array<int, string> $members) : bool
Parameters
$members : array<int, string>
Return values
bool

isRichTextUnion()

private static isRichTextUnion(ReflectionUnionType $type) : bool
Parameters
$type : ReflectionUnionType
Return values
bool

loadArrayValue()

private static loadArrayValue(ReflectionParameter $param, array<string|int, mixed> $value, Bot|null $bot) : array<string|int, mixed>
Parameters
$param : ReflectionParameter
$value : array<string|int, mixed>
$bot : Bot|null
Return values
array<string|int, mixed>

loadPhpdocValue()

private static loadPhpdocValue(string $phpdocType, mixed $value, Bot|null $bot) : mixed
Parameters
$phpdocType : string
$value : mixed
$bot : Bot|null

loadRichTextValue()

private static loadRichTextValue(mixed $value, Bot|null $bot) : mixed
Parameters
$value : mixed
$bot : Bot|null

loadTelegramObjectValue()

private static loadTelegramObjectValue(TelegramObject> $class, array<string|int, mixed> $value, Bot|null $bot) : TelegramObject
Parameters
$class : TelegramObject>
$value : array<string|int, mixed>
$bot : Bot|null
Return values
TelegramObject

loadValue()

private static loadValue(ReflectionParameter $param, mixed $value, Bot|null $bot) : mixed
Parameters
$param : ReflectionParameter
$value : mixed
$bot : Bot|null

phpdocClassName()

private static phpdocClassName(string $type) : null|TelegramObject>
Parameters
$type : string
Return values
null|TelegramObject>

phpdocScalarMatches()

private static phpdocScalarMatches(string $type, mixed $value) : bool
Parameters
$type : string
$value : mixed
Return values
bool

phpdocTypeForParam()

private static phpdocTypeForParam(ReflectionParameter $param) : string|null
Parameters
$param : ReflectionParameter
Return values
string|null

splitPhpdocUnion()

private static splitPhpdocUnion(string $phpdocType) : array<int, string>
Parameters
$phpdocType : string
Return values
array<int, string>

stripPhpdocNull()

private static stripPhpdocNull(string $phpdocType) : string
Parameters
$phpdocType : string
Return values
string

toStringKeyedArray()

Narrows an array with unknown key type to string-keyed for PHPStan.

private static toStringKeyedArray(array<string|int, mixed> $arr) : array<string, mixed>

Wire data from Telegram always uses string keys; this assertion is safe.

Parameters
$arr : array<string|int, mixed>
Return values
array<string, mixed>
On this page

Search results