UserShortcuts
Hand-authored shortcut helpers for `User`.
Loaded by HandAuthoredShortcutsIntegrator (Phase 2 codegen stage 8)
and stitched into the regenerated User class via a
use UserShortcuts; directive.
Mirrors aiogram's User.full_name, User.mention_html(), and
User.mention_markdown() accessors. The PHP-side helpers expose them
as ordinary methods (no @property magic) so PHPStan can resolve
them through the trait's signature.
The name parameter on the mention helpers lets the caller override
the display label without losing the underlying tg://user?id=…
link — useful when surfacing a "mention this user as …" prompt in a
bot conversation. Pass null (the default) to fall back to the
user's fullName().
Table of Contents
Properties
- $firstName : string
- $id : int
- $lastName : null|string
Methods
- fullName() : string
- The user's full display name: `firstName lastName` for a user with both names, otherwise just `firstName`. Whitespace is normalised so a missing `lastName` doesn't leak a trailing space.
- mentionHtml() : string
- HTML-formatted user mention: an `<a href="tg://user?id=…">name</a>` link Telegram clients render as a tappable mention.
- mentionMarkdown() : string
- Markdown-formatted user mention: `[name](tg://user?id=…)`.
Properties
$firstName
public
string
$firstName
promoted property on the using class
$id
public
int
$id
promoted property on the using class
$lastName
public
null|string
$lastName
promoted property on the using class
Methods
fullName()
The user's full display name: `firstName lastName` for a user with both names, otherwise just `firstName`. Whitespace is normalised so a missing `lastName` doesn't leak a trailing space.
public
fullName() : string
Return values
stringmentionHtml()
HTML-formatted user mention: an `<a href="tg://user?id=…">name</a>` link Telegram clients render as a tappable mention.
public
mentionHtml([string|null $name = null ]) : string
The display label is HTML-escaped with htmlspecialchars (default
ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5 flags) so a maliciously
crafted name can't break out of the <a> element. Pre-escape:
passing Foo<Bar> as the label produces Foo<Bar> inside
the anchor text.
Parameters
- $name : string|null = null
Return values
stringmentionMarkdown()
Markdown-formatted user mention: `[name](tg://user?id=…)`.
public
mentionMarkdown([string|null $name = null ]) : string
The label is passed through verbatim — Telegram's Markdown parser
tolerates a wider character set inside […] than HTML does inside
<a>, and aiogram's upstream helper takes the same approach. A
caller passing untrusted input should escape the few reserved
Markdown characters ([, ], \) themselves.
Parameters
- $name : string|null = null