You are here

protected function ProjectCoreCompatibility::getCompatibilityRanges in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/update/src/ProjectCoreCompatibility.php \Drupal\update\ProjectCoreCompatibility::getCompatibilityRanges()

Gets the compatibility ranges for a semantic version constraint.

Parameters

string $core_compatibility_constraint: A semantic version constraint.

Return value

array[] An array compatibility ranges. If a range array has 2 elements then this denotes a range of compatibility between and including the 2 versions. If the range has 1 element then it denotes compatibility with a single version.

1 call to ProjectCoreCompatibility::getCompatibilityRanges()
ProjectCoreCompatibility::createMessageFromCoreCompatibility in core/modules/update/src/ProjectCoreCompatibility.php
Creates core a compatibility message from a semantic version constraint.

File

core/modules/update/src/ProjectCoreCompatibility.php, line 202

Class

ProjectCoreCompatibility
Utility class to set core compatibility messages for project releases.

Namespace

Drupal\update

Code

protected function getCompatibilityRanges($core_compatibility_constraint) {
  $compatibility_ranges = [];
  foreach ($this->possibleCoreUpdateVersions as $possible_core_update_version) {
    if (Semver::satisfies($possible_core_update_version, $core_compatibility_constraint)) {
      if (empty($range)) {
        $range[] = $possible_core_update_version;
      }
      else {
        $range[1] = $possible_core_update_version;
      }
    }
    else {

      // If core version does not satisfy the constraint and there is a non
      // empty range, add it to the list of ranges.
      if (!empty($range)) {
        $compatibility_ranges[] = $range;

        // Start a new range.
        $range = [];
      }
    }
  }
  if (!empty($range)) {
    $compatibility_ranges[] = $range;
  }
  return $compatibility_ranges;
}