# SnapshotStore

> Provides JSON filesystem storage, manifest locking, atomic writes, and snapshot garbage collection.

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Storage](/docs/extensions/debug-core/reference/storage/index.md) › SnapshotStore

| final class | `PHPForge\Debug\Storage\SnapshotStore` |
| --- | --- |
| Source | [`src/Storage/SnapshotStore.php`](https://github.com/php-forge/debug-core/blob/main/src/Storage/SnapshotStore.php#L31) |

Provides JSON filesystem storage, manifest locking, atomic writes, and snapshot garbage collection.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a filesystem store with directory and file permission modes. | `SnapshotStore` |
| [`clear()`](#method-clear) | Removes stored manifests, snapshots, and temporary files. | `SnapshotStore` |
| [`loadManifest()`](#method-loadManifest) | Returns manifest entries ordered from newest to oldest. | `SnapshotStore` |
| [`loadManifestResult()`](#method-loadManifestResult) | Returns manifest entries and preserves any read diagnostic for observable error handling. | `SnapshotStore` |
| [`readSnapshot()`](#method-readSnapshot) | Returns a stored snapshot or `null` when the tag or persisted payload is invalid. | `SnapshotStore` |
| [`readSnapshotResult()`](#method-readSnapshotResult) | Returns a stored snapshot and preserves any read diagnostic for observable error handling. | `SnapshotStore` |
| [`writeSnapshot()`](#method-writeSnapshot) | Writes a snapshot, updates the manifest, and runs garbage collection under one exclusive lock. | `SnapshotStore` |
| [`writeSnapshotResult()`](#method-writeSnapshotResult) | Writes a snapshot and returns the already-hydrated committed manifest together with evicted entries. | `SnapshotStore` |

## Method details

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

```php
public function __construct(string $path, int $dirMode, int|null $fileMode)
```

Creates a filesystem store with directory and file permission modes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$path` | `string` | Storage directory path. |
| `$dirMode` | `int` | Directory permissions used when creating the storage path. |
| `$fileMode` | `int\|null` | File permissions or `null` to preserve the system default. |

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

```php
public function clear(): void
```

Removes stored manifests, snapshots, and temporary files.

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

```php
public function loadManifest(): array<string, PHPForge\Debug\Storage\RequestSummary>
```

Returns manifest entries ordered from newest to oldest.

**Returns**

`array<string,` [`RequestSummary`](/docs/extensions/debug-core/reference/storage/requestsummary/index.md)`>`: Newest entries first.

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

```php
public function loadManifestResult(): PHPForge\Debug\Storage\ManifestReadResult
```

Returns manifest entries and preserves any read diagnostic for observable error handling.

**Returns**

[`ManifestReadResult`](/docs/extensions/debug-core/reference/storage/manifestreadresult/index.md): Newest entries first plus an optional storage failure.

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

```php
public function readSnapshot(string $tag): PHPForge\Debug\Storage\DebugSnapshot|null
```

Returns a stored snapshot or `null` when the tag or persisted payload is invalid.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | `string` | Snapshot tag. |

**Returns**

[`DebugSnapshot`](/docs/extensions/debug-core/reference/storage/debugsnapshot/index.md)`|null`: Hydrated snapshot or `null` when the stored value is unavailable or invalid.

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

```php
public function readSnapshotResult(string $tag): PHPForge\Debug\Storage\SnapshotReadResult
```

Returns a stored snapshot and preserves any read diagnostic for observable error handling.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | `string` | Snapshot tag. |

**Returns**

[`SnapshotReadResult`](/docs/extensions/debug-core/reference/storage/snapshotreadresult/index.md): Snapshot, missing state, or storage failure.

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

```php
public function writeSnapshot(PHPForge\Debug\Storage\DebugSnapshot $snapshot, int $historySize): list<PHPForge\Debug\Storage\RequestSummary>
```

Writes a snapshot, updates the manifest, and runs garbage collection under one exclusive lock.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$snapshot` | [`DebugSnapshot`](/docs/extensions/debug-core/reference/storage/debugsnapshot/index.md) | Snapshot to persist. |
| `$historySize` | `int` | Maximum number of retained entries. |

**Returns**

`list<`[`RequestSummary`](/docs/extensions/debug-core/reference/storage/requestsummary/index.md)`>`: Entries evicted from the manifest.

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

```php
public function writeSnapshotResult(PHPForge\Debug\Storage\DebugSnapshot $snapshot, int $historySize): PHPForge\Debug\Storage\SnapshotWriteResult
```

Writes a snapshot and returns the already-hydrated committed manifest together with evicted entries.

Adapters that need the resulting manifest can consume this result without acquiring the lock and decoding the
index a second time.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$snapshot` | [`DebugSnapshot`](/docs/extensions/debug-core/reference/storage/debugsnapshot/index.md) | Snapshot to persist. |
| `$historySize` | `int` | Maximum number of retained entries. |

**Returns**

[`SnapshotWriteResult`](/docs/extensions/debug-core/reference/storage/snapshotwriteresult/index.md): Committed manifest and entries evicted from it.