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.

array[]
toArray() deprecated

A list of associative arrays representing the constraint.

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.

array[] toArray() deprecated

deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Only exists to provide a backwards compatibility layer.

A list of associative arrays representing the constraint.

Each containing the keys:

  • 'op': can be one of: '=', '==', '!=', '<>', '<', '<=', '>', or '>='.
  • 'version': A complete version, e.g. '4.5-beta3'.

Return Value

array[]

The constraint represented as an array.

See also

https://www.drupal.org/node/2756875

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.