# ApplyPreviewer

> Computes in memory what applying a provider mapping would write to its destination, without touching the disk.

[API reference](/docs/api/index.md) › [Scaffold](/docs/extensions/scaffold/reference/index.md) › [Services](/docs/extensions/scaffold/reference/services/index.md) › ApplyPreviewer

| final readonly class | `PHPForge\Scaffold\Services\ApplyPreviewer` |
| --- | --- |
| Source | [`src/Services/ApplyPreviewer.php`](https://github.com/php-forge/scaffold/blob/main/src/Services/ApplyPreviewer.php#L24) |

Computes in memory what applying a provider mapping would write to its destination, without touching the disk.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`preview()`](#method-preview) | Returns the current and proposed content of the mapping destination: the stub for `replace` and `preserve`, the merge result for `append`, and the prepended block for `prepend`. | `ApplyPreviewer` |

## Method details

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

```php
public function preview(PHPForge\Scaffold\Manifest\FileMapping $mapping, string $projectRoot, PHPForge\Scaffold\Services\LockEntry|null $entry = null): PHPForge\Scaffold\Services\ApplyPreview
```

Returns the current and proposed content of the mapping destination: the stub for `replace` and `preserve`, the
merge result for `append`, and the prepended block for `prepend`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$mapping` | [`PHPForge\Scaffold\Manifest\FileMapping`](/docs/extensions/scaffold/reference/manifest/filemapping/index.md) | Validated mapping to preview. |
| `$projectRoot` | `string` | Absolute path to the project root. |
| `$entry` | `PHPForge\Scaffold\Services\LockEntry\|null` | Lock entry of the destination, or `null` when it is untracked. |

**Returns**

[`ApplyPreview`](/docs/extensions/scaffold/reference/services/applypreview/index.md): Current and proposed content of the destination, with its `replace` and `preserve` flags.

**Throws**

- [`RuntimeException`](https://www.php.net/manual/en/class.runtimeexception.php): when the stub is missing or a file cannot be read or hashed.