Skip to content
PHP Ecosystem
Explore

ToolbarDataMapper

API reference › Debug › ToolbarDataMapper

final readonly classyii\debug\ToolbarDataMapper
Sourcesrc/ToolbarDataMapper.php

Maps Yii2 panel envelopes to the shared typed toolbar contract.

Start from create() with the values the toolbar cannot render without, then layer the optional chrome through the immutable with*() methods, which mirror ToolbarData. map() closes the chain.

MethodDescriptionDefined by
create() staticCreates a mapper for a capture, ready for immutable enrichment.ToolbarDataMapper
map()Creates the JSON-ready toolbar payload.ToolbarDataMapper
withBranding()Returns a copy carrying the brand assets and the version labels.ToolbarDataMapper
withNavigation()Returns a copy carrying the debugger navigation URLs.ToolbarDataMapper
withPresentation()Returns a copy carrying the drawer presentation settings.ToolbarDataMapper
public static function create(string $tag, string $title): self

Creates a mapper for a capture, ready for immutable enrichment.

Parameters

ParameterTypeDescription
$tagstringTag of the capture the toolbar links to.
$titlestringTitle of the captured request.

Returns

self: Mapper carrying only the mandatory toolbar identity.

public function map(array<string, yii\debug\Panel> $panels): array{configUrl: string, defaultHeight: int, iconBaseUrl: string, indexUrl: string, items: list<array<string, mixed>>, logo: string|null, logoFallback: string|null, phpInfoUrl: string|null, phpVersion: string|null, position: string, tag: string, title: string, yiiVersion: string|null}

Creates the JSON-ready toolbar payload.

Every panel is serialized through the Debug Core DTOs, so fields outside the id, title, url, icon, and items schema are dropped. A panel whose envelope breaks that schema renders a single error chip carrying Message::TOOLBAR_ENVELOPE_INVALID as its tooltip, keeping the failure contained to its own chip.

Chips are emitted in the order the module registered the panels, which the shared registration policy already resolved, so the toolbar mirrors the sidebar grouping. Every panel the module registry classifies as an extension, and every panel it does not list (a raw JSON fallback), carries extension: true, so the shared toolbar groups it under its Extensions menu; built-in panels omit the key and stay inline.

Parameters

ParameterTypeDescription
$panelsarray<string, Panel>Registered Yii2 panels keyed by ID, in display order.

Returns

array{configUrl: string, defaultHeight: int, iconBaseUrl: string, indexUrl: string, items: list<array<string, mixed>>, logo: string|null, logoFallback: string|null, phpInfoUrl: string|null, phpVersion: string|null, position: string, tag: string, title: string, yiiVersion: string|null}: Payload consumed by the shared toolbar runtime.

public function withBranding(string|null $logo, string|null $logoFallback = null, string|null $phpVersion = null, string|null $yiiVersion = null): self

Returns a copy carrying the brand assets and the version labels.

Parameters

ParameterTypeDescription
$logostring|nullLogo as a data URI, or null to fall back.
$logoFallbackstring|nullLogo used when the primary one is unavailable, or null for none.
$phpVersionstring|nullPHP version label, or null when unavailable.
$yiiVersionstring|nullYii version label, or null when unavailable.

Returns

self: Mapper with the branding applied.

public function withNavigation(string $indexUrl, string|null $configUrl = null, string|null $phpInfoUrl = null): self

Returns a copy carrying the debugger navigation URLs.

An omitted configuration URL falls back to the history URL, which Debug Core requires to be non-null.

Parameters

ParameterTypeDescription
$indexUrlstringURL of the history page.
$configUrlstring|nullURL of the configuration panel, or null to reuse the history URL.
$phpInfoUrlstring|nullURL of the phpinfo() page, or null when disabled.

Returns

self: Mapper with the navigation applied.

public function withPresentation(string $position, int $defaultHeight, string $iconBaseUrl = ''): self

Returns a copy carrying the drawer presentation settings.

Parameters

ParameterTypeDescription
$positionstringEdge the toolbar docks to.
$defaultHeightintCollapsed toolbar height, in pixels.
$iconBaseUrlstringBase URL the panel icons resolve against.

Returns

self: Mapper with the presentation applied.