phpbotgram

CommandObject
in package

Read onlyYes
FinalYes

Readonly DTO carrying the parsed pieces of a Telegram slash-command (`/cmd@mention args`). Produced by {@see Command}::__invoke and injected into the handler kwargs under the `command` key.

Mirrors upstream aiogram.filters.command.CommandObject (aiogram/filters/command.py:202-237). Field order matches the upstream @dataclass declaration: prefix, command, mention, args, regexp_match, magic_result.

Field role summary:

  • prefix: leading character(s) before the command name (/, !, …). A Command filter can register multiple prefixes; the matched one ends up here.
  • command: command name without prefix or @mention.
  • mention: optional @-suffixed bot mention, normalised (the leading @ is stripped) — null when the input had no @suffix. Upstream issue aiogram/aiogram#1013 makes the absence explicit; we mirror that in the parser by storing null (not '') when no mention was present.
  • args: post-command remainder verbatim; null if the user wrote no args at all. Upstream's text.split(maxsplit=1) is mirrored by preg_split('/\s+/', $rest, 2) in Command::parseCommand, which consumes the first run of whitespace and preserves the tail.
  • regexpMatch: the regex match payload if the command was matched via a regex pattern. Surface only — populated in Phase 4.5+ when the Command(string|Regex|BotCommand ...) variants land.
  • magicResult: result of a MagicFilter-based post-validation. Also Phase 4.5+; surface today so a follow-up patch can drop the field in without churning the DTO shape.

Both regexpMatch/magicResult mirror upstream's repr=False semantic by simply staying out of any __toString-style helper — there's no stable PHP convention for excluding fields from var_dump, but no production code path inspects them anyway.

Table of Contents

Properties

$args  : string|null
$command  : string
$magicResult  : mixed
$mention  : string|null
$prefix  : string
$regexpMatch  : array<string|int, mixed>|null

Methods

__construct()  : mixed
mentioned()  : bool
Whether the command carried an `@bot_username` mention. Mirrors upstream's derived `mentioned` property at `aiogram/filters/command.py:220-225`.
mentionWithoutPrefix()  : string|null
Mention with any leading `@` stripped, or `null` when no mention is stored. Matches upstream's `mention_without_prefix` convenience used by `Command.validate_mention` when comparing against `bot.me().username`.
text()  : string
Reassemble the original textual command from the parsed parts. Mirrors upstream's `text` property (`aiogram/filters/command.py:228-237`) and provides a round-trip for logging / display purposes.

Properties

$regexpMatch

public array<string|int, mixed>|null $regexpMatch = null

Methods

__construct()

public __construct([string $prefix = '/' ][, string $command = '' ][, string|null $mention = null ][, string|null $args = null ][, array<int|string, mixed>|null $regexpMatch = null ][, mixed $magicResult = null ]) : mixed
Parameters
$prefix : string = '/'
$command : string = ''
$mention : string|null = null
$args : string|null = null
$regexpMatch : array<int|string, mixed>|null = null

Capture groups from a regex match, when the matching command pattern was a regex (Phase 4.5+). Null otherwise.

$magicResult : mixed = null

Result of a magic-filter post-validation (Phase 4.5+). Null otherwise.

mentioned()

Whether the command carried an `@bot_username` mention. Mirrors upstream's derived `mentioned` property at `aiogram/filters/command.py:220-225`.

public mentioned() : bool

Implementation note: Python uses bool(self.mention) which collapses empty strings to false. We mirror by combining the null check with an explicit emptiness guard so mention: '' (defensive callers) does not suddenly count as mentioned.

Return values
bool

mentionWithoutPrefix()

Mention with any leading `@` stripped, or `null` when no mention is stored. Matches upstream's `mention_without_prefix` convenience used by `Command.validate_mention` when comparing against `bot.me().username`.

public mentionWithoutPrefix() : string|null

The current parser already strips the @ before storing, but this helper is the canonical accessor so user-land code can recover the unprefixed form from a CommandObject built by hand (tests, fixtures).

Return values
string|null

text()

Reassemble the original textual command from the parsed parts. Mirrors upstream's `text` property (`aiogram/filters/command.py:228-237`) and provides a round-trip for logging / display purposes.

public text() : string
Return values
string
On this page

Search results