# MailSnapshot

> Canonical Mail panel snapshot holding the captured messages in their typed form.

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Panel](/docs/extensions/debug-core/reference/panel/index.md) › [Mail](/docs/extensions/debug-core/reference/panel/mail/index.md) › MailSnapshot

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

Canonical Mail panel snapshot holding the captured messages in their typed form.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a mail snapshot from captured messages. | `MailSnapshot` |
| [`capture()`](#method-capture) static | Narrows the captured `EVENT_AFTER_SEND` payloads into typed messages. | `MailSnapshot` |
| [`entries()`](#method-entries) | Returns the captured messages. | `MailSnapshot` |
| [`fromArray()`](#method-fromArray) static | Narrows the persisted mail payload into a typed snapshot. | `MailSnapshot` |
| [`jsonSerialize()`](#method-jsonSerialize) | Serializes the snapshot into its persisted payload. | `MailSnapshot` |

## Method details

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

```php
public function __construct(list<PHPForge\Debug\Panel\Mail\MailEntry> $entries)
```

Creates a mail snapshot from captured messages.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$entries` | `list<`[`MailEntry`](/docs/extensions/debug-core/reference/panel/mail/mailentry/index.md)`>` | Captured messages in send order. |

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

```php
public static function capture(array<array-key, mixed> $messages): self
```

Narrows the captured `EVENT_AFTER_SEND` payloads into typed messages.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$messages` | `array<array-key, mixed>` | Captured payloads in send order; non-array entries are dropped. |

**Returns**

`self`: Snapshot carrying the typed messages.

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

```php
public function entries(): list<PHPForge\Debug\Panel\Mail\MailEntry>
```

Returns the captured messages.

**Returns**

`list<`[`MailEntry`](/docs/extensions/debug-core/reference/panel/mail/mailentry/index.md)`>`: Captured messages in send order.

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

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

Narrows the persisted mail payload into a typed snapshot.

**Parameters**

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

**Returns**

`self`: Snapshot carrying the persisted messages.

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

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

Serializes the snapshot into its persisted payload.

**Returns**

`array<string, mixed>`: Payload carrying the messages under the `entries` key.