Skip to content
docsv0.8.0

CapabilityRequirement

A `requires` capability record. Declares a HARD dependency on a contract: at least one installed provider must satisfy `interface` within the semver `constraint` range. `oneOf` optionally lists provider capability ids any of which satisfies the requirement. Legacy bare-FQCN declarations are accepted via {@see fromInterface()}. The primary constructor validates exactly like {@see fromArray()} does: `id` and `interface` must be non-empty. There is no "trusted, pre-validated" construction path — hand-building a record is validated identically to parsing one from a manifest.

CapabilityRequirement::__construct()

public function __construct(string $id, string $interface, string $constraint = '*', array $oneOf = []):

Parameters

Parameters of __construct()
NameTypeDescription
$idstring
$interfacestring
$constraintstring
$oneOflist<string>

Throws

\InvalidArgumentException If `id` or `interface` is empty.

CapabilityRequirement::fromArray()

public static function fromArray(array $record): self

Build a requirement record from a decoded `requires` manifest entry. Coerces raw (possibly untyped) array values to their expected shape — defaulting `constraint` to `*` and normalizing `oneOf` to a list of non-empty strings; validation of the result (`id`/`interface` non-empty) happens in the constructor, not here.

Parameters

Parameters of fromArray()
NameTypeDescription
$recordarray<string, mixed>

Throws

\InvalidArgumentException If `id` or `interface` is empty.

CapabilityRequirement::fromInterface()

public static function fromInterface(string $interface): self

Wrap a legacy bare-FQCN declaration as an any-version requirement.

Parameters

Parameters of fromInterface()
NameTypeDescription
$interfacestring

CapabilityRequirement::parse()

public static function parse(array|string $record): self

Parse a `requires` manifest entry in either the legacy bare-FQCN string form or the structured-record array form, dispatching to {@see fromInterface()} or {@see fromArray()}.

Parameters

Parameters of parse()
NameTypeDescription
$record(string | array<string, mixed>)