# ToolbarDataFactory

> Creates toolbar data from framework metadata and captured extension panels.

[API reference](/docs/api/index.md) › [Yii3 Debug](/docs/extensions/yii3-debug/reference/index.md) › ToolbarDataFactory

| final class | `Yii3\Debug\ToolbarDataFactory` |
| --- | --- |
| Source | [`src/ToolbarDataFactory.php`](https://github.com/yii3/debug/blob/main/src/ToolbarDataFactory.php#L41) |

Creates toolbar data from framework metadata and captured extension panels.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a toolbar-data factory with asset URL and debugger route configuration. | `ToolbarDataFactory` |
| [`create()`](#method-create) | Builds the toolbar chrome for a capture, without its panels. | `ToolbarDataFactory` |
| [`createForSnapshot()`](#method-createForSnapshot) | Builds the complete toolbar payload for a capture, panels included. | `ToolbarDataFactory` |
| [`withExtensionPanels()`](#method-withExtensionPanels) | Returns a copy carrying the extension panels shown on the toolbar. | `ToolbarDataFactory` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(Yiisoft\Assets\AssetManager $assetManager, Yii3\Debug\Middleware\ToolbarOptions $options = new \Yii3\Debug\Middleware\ToolbarOptions())
```

Creates a toolbar-data factory with asset URL and debugger route configuration.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$assetManager` | `Yiisoft\Assets\AssetManager` | Manager resolving the published URLs of the toolbar assets. |
| `$options` | [`Yii3\Debug\Middleware\ToolbarOptions`](/docs/extensions/yii3-debug/reference/middleware/toolbaroptions/index.md) | Settings carrying the route prefix every debugger URL is built on and the toolbar presentation. |

### create() <span id="method-create"></span>

```php
public function create(string $tag): PHPForge\Debug\Toolbar\ToolbarData
```

Builds the toolbar chrome for a capture, without its panels.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | `string` | Tag of the capture the toolbar links to. |

**Returns**

[`ToolbarData`](https://github.com/php-forge/debug-core/blob/b70459f033a1d7a1c5edf7951029aad2061986dd/src/Toolbar/ToolbarData.php): Toolbar payload carrying navigation, presentation, and branding.

### createForSnapshot() <span id="method-createForSnapshot"></span>

```php
public function createForSnapshot(PHPForge\Debug\Storage\DebugSnapshot $snapshot): PHPForge\Debug\Toolbar\ToolbarData
```

Builds the complete toolbar payload for a capture, panels included.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$snapshot` | `PHPForge\Debug\Storage\DebugSnapshot` | Capture the toolbar describes. |

**Returns**

[`ToolbarData`](https://github.com/php-forge/debug-core/blob/b70459f033a1d7a1c5edf7951029aad2061986dd/src/Toolbar/ToolbarData.php): Toolbar payload including every registered extension panel.

### withExtensionPanels() <span id="method-withExtensionPanels"></span>

```php
public function withExtensionPanels(iterable<Yii3\Debug\Panel\ExtensionPanelInterface> $extensionPanels): self
```

Returns a copy carrying the extension panels shown on the toolbar.

Chips follow the order given, which is the order the sidebar lists the same panels in: the container passes
[`ExtensionRegistry::panelsWithBuiltIns()`](/docs/extensions/yii3-debug/reference/extensionregistry/index.md#method-panelsWithBuiltIns), built-ins first in [`BuiltInPanels::IDS`](/docs/extensions/yii3-debug/reference/panel/builtinpanels/index.md#const-IDS) order.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$extensionPanels` | `iterable<`[`Yii3\Debug\Panel\ExtensionPanelInterface`](/docs/extensions/yii3-debug/reference/panel/extensionpanelinterface/index.md)`>` | Optional extension presenters in toolbar order. |

**Returns**

`self`: Factory with the panels applied.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): when a panel ID is empty or duplicated.