You are here

public function VersionParser::parseConstraints in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/composer/semver/src/VersionParser.php \Composer\Semver\VersionParser::parseConstraints()

Parses as constraint string into LinkConstraint objects.

Parameters

string $constraints:

Return value

ConstraintInterface

File

vendor/composer/semver/src/VersionParser.php, line 214

Class

VersionParser
Version parser.

Namespace

Composer\Semver

Code

public function parseConstraints($constraints) {
  $prettyConstraint = $constraints;
  if (preg_match('{^([^,\\s]*?)@(' . implode('|', self::$stabilities) . ')$}i', $constraints, $match)) {
    $constraints = empty($match[1]) ? '*' : $match[1];
  }
  if (preg_match('{^(dev-[^,\\s@]+?|[^,\\s@]+?\\.x-dev)#.+$}i', $constraints, $match)) {
    $constraints = $match[1];
  }
  $orConstraints = preg_split('{\\s*\\|\\|?\\s*}', trim($constraints));
  $orGroups = array();
  foreach ($orConstraints as $constraints) {
    $andConstraints = preg_split('{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}', $constraints);
    if (count($andConstraints) > 1) {
      $constraintObjects = array();
      foreach ($andConstraints as $constraint) {
        foreach ($this
          ->parseConstraint($constraint) as $parsedConstraint) {
          $constraintObjects[] = $parsedConstraint;
        }
      }
    }
    else {
      $constraintObjects = $this
        ->parseConstraint($andConstraints[0]);
    }
    if (1 === count($constraintObjects)) {
      $constraint = $constraintObjects[0];
    }
    else {
      $constraint = new MultiConstraint($constraintObjects);
    }
    $orGroups[] = $constraint;
  }
  if (1 === count($orGroups)) {
    $constraint = $orGroups[0];
  }
  else {
    $constraint = new MultiConstraint($orGroups, false);
  }
  $constraint
    ->setPrettyString($prettyConstraint);
  return $constraint;
}