# Requirement

> Represents one dependency requirement fed to the native resolver: a package name, its npm specification, and the manifest or package that declared it.

[API reference](/docs/api/index.md) › [Foxy](/docs/extensions/foxy/reference/index.md) › [Native](/docs/extensions/foxy/reference/native/index.md) › Requirement

| final readonly class | `Foxy\Native\Requirement` |
| --- | --- |
| Source | [`src/Native/Requirement.php`](https://github.com/php-forge/foxy/blob/main/src/Native/Requirement.php#L11) |

Represents one dependency requirement fed to the native resolver: a package name, its npm specification, and the
manifest or package that declared it.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-name"></span>`$name` readonly constructor | `string` | Package name, scoped names included (`@scope/name`). | `Requirement` |
| <span id="property-optional"></span>`$optional` readonly constructor | `bool` | Whether an unsatisfiable requirement is skipped with a warning instead of failing. Default: `false`. | `Requirement` |
| <span id="property-optionalRoot"></span>`$optionalRoot` readonly constructor | `string\|null` | Selection (`name@version`) of the optional package whose subtree declared the requirement, or `null` outside any optional subtree. Default: `null`. | `Requirement` |
| <span id="property-source"></span>`$source` readonly constructor | `string` | Declaring origin: `''` for the root manifest, the local package name, or `name@version`. | `Requirement` |
| <span id="property-spec"></span>`$spec` readonly constructor | `string` | Npm specification as written by the declaring manifest (range, version, or dist-tag). | `Requirement` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Describes one dependency constraint for the native resolver. | `Requirement` |

## Method details

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

```php
public function __construct(string $name, string $spec, string $source, bool $optional = false, string|null $optionalRoot = null)
```

Describes one dependency constraint for the native resolver.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Package name, scoped names included (`@scope/name`). |
| `$spec` | `string` | Npm specification as written by the declaring manifest (range, version, or dist-tag). |
| `$source` | `string` | Declaring origin: `''` for the root manifest, the local package name, or `name@version`. |
| `$optional` | `bool` | Whether an unsatisfiable requirement is skipped with a warning instead of failing. |
| `$optionalRoot` | `string\|null` | Selection (`name@version`) of the optional package whose subtree declared the requirement, or `null` outside any optional subtree. |