class Constraint (View source)

A value object representing a Drupal version constraint.

Properties

protected string $constraint

The constraint represented as a string. For example '>=8.x-5.x'.

protected array[] $constraintArray

A list of associative arrays representing the constraint.

Methods

__construct(string $constraint, string $core_compatibility)

Constraint constructor.

string
__toString()

Gets the constraint as a string.

bool
isCompatible(string $version)

Determines if the provided version is satisfied by this constraint.

Details

__construct(string $constraint, string $core_compatibility)

Constraint constructor.

Parameters

string $constraint

The constraint string to create the object from. For example, '>8.x-1.1'.

string $core_compatibility

Core compatibility declared for the current version of Drupal core. Normally this is set to \Drupal::CORE_COMPATIBILITY by the caller.

string __toString()

Gets the constraint as a string.

Can be used in the UI for reporting incompatibilities.

Return Value

string

The constraint as a string.

bool isCompatible(string $version)

Determines if the provided version is satisfied by this constraint.

Parameters

string $version

The version to check, for example '4.2'.

Return Value

bool

TRUE if the provided version is satisfied by this constraint, FALSE if not.