# ProjectConfig

> Represents the consumer settings read from the project composer.json: extra.scaffold and config.vendor-dir.

[API reference](/docs/api/index.md) › [Scaffold](/docs/extensions/scaffold/reference/index.md) › [Config](/docs/extensions/scaffold/reference/config/index.md) › ProjectConfig

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

Represents the consumer settings read from the project `composer.json`: `extra.scaffold` and `config.vendor-dir`.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-allowedPackages"></span>`$allowedPackages` readonly constructor | `list<string>` | Package names allowed to write scaffold files, in declaration order. Default: `[]`. | `ProjectConfig` |
| <span id="property-auto"></span>`$auto` readonly constructor | `bool` | Whether the Composer hooks scaffold automatically. Default: `true`. | `ProjectConfig` |
| <span id="property-declared"></span>`$declared` readonly constructor | `bool` | Whether `extra.scaffold` is an object. Default: `false`. | `ProjectConfig` |
| <span id="property-ignoredEntries"></span>`$ignoredEntries` readonly constructor | `int` | Number of non-string `allowed-packages` entries that were ignored. Default: `0`. | `ProjectConfig` |
| <span id="property-vendorDir"></span>`$vendorDir` readonly constructor | `string\|null` | Non-empty `config.vendor-dir` as written in `composer.json`, or `null` when unset. Default: `null`. | `ProjectConfig` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates consumer settings from scaffold configuration and the configured vendor-directory value. | `ProjectConfig` |
| [`fromComposerJson()`](#method-fromComposerJson) static | Reads the configuration from a `composer.json` file. | `ProjectConfig` |
| [`fromExtra()`](#method-fromExtra) static | Reads the configuration from the `extra` section of the root package; only an explicit `false` in `auto` disables the Composer hooks. | `ProjectConfig` |
| [`isAllowed()`](#method-isAllowed) | Returns whether `$packageName` is listed in `allowed-packages`. | `ProjectConfig` |

## Method details

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

```php
public function __construct(list<string> $allowedPackages = [], bool $auto = true, int $ignoredEntries = 0, bool $declared = false, string|null $vendorDir = null)
```

Creates consumer settings from scaffold configuration and the configured vendor-directory value.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$allowedPackages` | `list<string>` | Package names allowed to write scaffold files, in declaration order. |
| `$auto` | `bool` | Whether the Composer hooks scaffold automatically. |
| `$ignoredEntries` | `int` | Number of non-string `allowed-packages` entries that were ignored. |
| `$declared` | `bool` | Whether `extra.scaffold` is an object. |
| `$vendorDir` | `string\|null` | Non-empty `config.vendor-dir` as written in `composer.json`, or `null` when unset. |

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

```php
public static function fromComposerJson(string $path): self
```

Reads the configuration from a `composer.json` file.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$path` | `string` | Absolute path to the project `composer.json`. |

**Returns**

`self`: Configuration from `extra.scaffold` and `config.vendor-dir`, or the defaults when they are absent.

**Throws**

- [`RuntimeException`](https://www.php.net/manual/en/class.runtimeexception.php): when the file is missing, unreadable, or not a JSON object.

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

```php
public static function fromExtra(mixed[] $extra): self
```

Reads the configuration from the `extra` section of the root package; only an explicit `false` in `auto`
disables the Composer hooks.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$extra` | `mixed[]` | `extra` section of the root package. |

**Returns**

`self`: Configuration from `extra.scaffold`, or the defaults when it is absent or not an object.

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

```php
public function isAllowed(string $packageName): bool
```

Returns whether `$packageName` is listed in `allowed-packages`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$packageName` | `string` | Package name to check. |

**Returns**

`bool`: `true` when the package is allowed to write scaffold files, `false` otherwise.