# RouterSnapshot

> Canonical routing trace snapshot, with the URL-rule trace resolved into typed rows at capture time.

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Panel](/docs/extensions/debug-core/reference/panel/index.md) › [Router](/docs/extensions/debug-core/reference/panel/router/index.md) › RouterSnapshot

| final readonly class | `PHPForge\Debug\Panel\Router\RouterSnapshot` |
| --- | --- |
| Implements | [`PHPForge\Debug\Storage\PanelSnapshot`](/docs/extensions/debug-core/reference/storage/panelsnapshot/index.md) |
| Source | [`src/Panel/Router/RouterSnapshot.php`](https://github.com/php-forge/debug-core/blob/main/src/Panel/Router/RouterSnapshot.php#L16) |

Canonical routing trace snapshot, with the URL-rule trace resolved into typed rows at capture time.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-action"></span>`$action` readonly constructor | `string\|null` | Dispatched action descriptor, or `null` when routing resolved none. | `RouterSnapshot` |
| <span id="property-message"></span>`$message` readonly constructor | `string\|null` | Routing trace message emitted by the URL manager, or `null` when it emitted none. | `RouterSnapshot` |
| <span id="property-route"></span>`$route` readonly constructor | `string` | Route the request resolved to. | `RouterSnapshot` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a routing snapshot from the captured rule trace. | `RouterSnapshot` |
| [`capture()`](#method-capture) static | Replays the URL-manager trace into typed rows, dropping the duplicate emitted by nested REST rules. | `RouterSnapshot` |
| [`entries()`](#method-entries) | Returns the URL rules inspected while resolving the route. | `RouterSnapshot` |
| [`fromArray()`](#method-fromArray) static | Narrows the persisted routing payload into a typed snapshot. | `RouterSnapshot` |
| [`hasMatch()`](#method-hasMatch) | Returns whether any inspected rule reported a successful match. | `RouterSnapshot` |
| [`jsonSerialize()`](#method-jsonSerialize) | Returns the panel snapshot for JSON serialization. | `RouterSnapshot` |

## Method details

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

```php
public function __construct(string|null $action, string $route, string|null $message, list<PHPForge\Debug\Panel\Router\CurrentRouteLogRow> $entries)
```

Creates a routing snapshot from the captured rule trace.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | `string\|null` |  |
| `$route` | `string` |  |
| `$message` | `string\|null` |  |
| `$entries` | `list<`[`CurrentRouteLogRow`](/docs/extensions/debug-core/reference/panel/router/currentroutelogrow/index.md)`>` |  |

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

```php
public static function capture(string|null $action, array<int, array<int|string, mixed>> $messages, string $route): self
```

Replays the URL-manager trace into typed rows, dropping the duplicate emitted by nested REST rules.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | `string\|null` |  |
| `$messages` | `array<int, array<int\|string, mixed>>` | Raw routing log tuples in capture order. |
| `$route` | `string` |  |

**Returns**

`self`

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

```php
public function entries(): list<PHPForge\Debug\Panel\Router\CurrentRouteLogRow>
```

Returns the URL rules inspected while resolving the route.

**Returns**

`list<`[`CurrentRouteLogRow`](/docs/extensions/debug-core/reference/panel/router/currentroutelogrow/index.md)`>`: Rules inspected during routing, in inspection order.

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

```php
public static function fromArray(mixed $data, string $path): self
```

Narrows the persisted routing payload into a typed snapshot.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$data` | `mixed` | Persisted payload, expected to be an object carrying the declared shape. |
| `$path` | `string` | JSON path of the payload, used to report a malformed capture. |

**Returns**

`self`: Snapshot carrying the resolved route and the inspected rules.

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

```php
public function hasMatch(): bool
```

Returns whether any inspected rule reported a successful match.

**Returns**

`bool`

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

```php
public function jsonSerialize(): array<string, mixed>
```

Returns the panel snapshot for JSON serialization.

**Returns**

`array<string, mixed>`