function SemanticVersion::majorMinorConstraint

Same name and namespace in other branches
  1. 9 composer/Util/SemanticVersion.php \Drupal\Composer\Util\SemanticVersion::majorMinorConstraint()
  2. 10 composer/Util/SemanticVersion.php \Drupal\Composer\Util\SemanticVersion::majorMinorConstraint()

Given a version, generate a loose ^major.minor constraint.

Parameters

string $version: Semantic version string. Example: 9.5.0-beta23.

Return value

string Constraint string for major and minor. Example: ^9.5

1 call to SemanticVersion::majorMinorConstraint()
ComponentGenerator::getPackage in composer/Generator/ComponentGenerator.php
Reconcile component dependencies with core.

File

composer/Util/SemanticVersion.php, line 19

Class

SemanticVersion
Utility methods for manipulating semantic versions.

Namespace

Drupal\Composer\Util

Code

public static function majorMinorConstraint(string $version) : string {
    preg_match('/^(\\d+)\\.(\\d+)\\.\\d+/', $version, $matches);
    return '^' . $matches[1] . '.' . $matches[2];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.