# ManifestLoader

> Loads a provider manifest, inline in extra.scaffold or in the provider file named by extra.scaffold.manifest, and expands it into file mappings.

[API reference](/docs/api/index.md) › [Scaffold](/docs/extensions/scaffold/reference/index.md) › [Manifest](/docs/extensions/scaffold/reference/manifest/index.md) › ManifestLoader

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

Loads a provider manifest, inline in `extra.scaffold` or in the provider file named by `extra.scaffold.manifest`, and
expands it into file mappings.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a loader with its schema validator and mapping expander. | `ManifestLoader` |
| [`loadFromExtra()`](#method-loadFromExtra) | Loads the provider manifest from the `extra` section of a provider package and expands it into file mappings, without Composer's package classes. | `ManifestLoader` |
| [`loadFromPath()`](#method-loadFromPath) | Loads the provider manifest from the `composer.json` at the provider root and expands it into file mappings, exactly like [`ManifestLoader::loadFromExtra()`](/docs/extensions/scaffold/reference/manifest/manifestloader/index.md#method-loadFromExtra). | `ManifestLoader` |

## Method details

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

```php
public function __construct(PHPForge\Scaffold\Manifest\ManifestSchema $schema, PHPForge\Scaffold\Manifest\ManifestExpander $expander)
```

Creates a loader with its schema validator and mapping expander.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | [`ManifestSchema`](/docs/extensions/scaffold/reference/manifest/manifestschema/index.md) | Validates the manifest. |
| `$expander` | [`ManifestExpander`](/docs/extensions/scaffold/reference/manifest/manifestexpander/index.md) | Expands the validated manifest into file mappings. |

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

```php
public function loadFromExtra(mixed[] $extra, string $packageName, string $packagePath): list<PHPForge\Scaffold\Manifest\FileMapping>
```

Loads the provider manifest from the `extra` section of a provider package and expands it into file mappings,
without Composer's package classes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$extra` | `mixed[]` | `extra` section of the provider package. |
| `$packageName` | `string` | Composer package name of the provider. |
| `$packagePath` | `string` | Absolute path to the provider root. |

**Returns**

`list<`[`FileMapping`](/docs/extensions/scaffold/reference/manifest/filemapping/index.md)`>`: File mappings; empty when `$extra` declares no `scaffold` object.

**Throws**

- [`RuntimeException`](https://www.php.net/manual/en/class.runtimeexception.php): when the manifest file is missing or unreadable, the manifest is invalid, or a `copy[]` path does not exist.
- [`JsonException`](https://www.php.net/manual/en/class.jsonexception.php): when the external manifest file is not valid JSON.

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

```php
public function loadFromPath(string $packageName, string $packagePath): list<PHPForge\Scaffold\Manifest\FileMapping>
```

Loads the provider manifest from the `composer.json` at the provider root and expands it into file mappings,
exactly like [`ManifestLoader::loadFromExtra()`](/docs/extensions/scaffold/reference/manifest/manifestloader/index.md#method-loadFromExtra).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$packageName` | `string` | Composer package name of the provider. |
| `$packagePath` | `string` | Absolute path to the provider root. |

**Returns**

`list<`[`FileMapping`](/docs/extensions/scaffold/reference/manifest/filemapping/index.md)`>`: File mappings; empty when the package declares no `extra.scaffold` object.

**Throws**

- [`RuntimeException`](https://www.php.net/manual/en/class.runtimeexception.php): when the provider `composer.json` or the manifest file is missing, unreadable or invalid, or a `copy[]` path does not exist.
- [`JsonException`](https://www.php.net/manual/en/class.jsonexception.php): when the provider `composer.json` or the external manifest file is not valid JSON.