Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. VersionConstraintParser.php

function VersionConstraintParser::parse

Throws

UnsupportedVersionConstraintException

1 call to VersionConstraintParser::parse()
VersionConstraintParser::handleOrGroup in vendor/phar-io/version/src/VersionConstraintParser.php

File

vendor/phar-io/version/src/VersionConstraintParser.php, line 16

Class

VersionConstraintParser

Namespace

PharIo\Version

Code

public function parse(string $value) : VersionConstraint {
    if (\strpos($value, '|') !== false) {
        return $this->handleOrGroup($value);
    }
    if (!\preg_match('/^[\\^~*]?v?[\\d.*]+(?:-.*)?$/i', $value)) {
        throw new UnsupportedVersionConstraintException(\sprintf('Version constraint %s is not supported.', $value));
    }
    switch ($value[0]) {
        case '~':
            return $this->handleTildeOperator($value);
        case '^':
            return $this->handleCaretOperator($value);
    }
    $constraint = new VersionConstraintValue($value);
    if ($constraint->getMajor()
        ->isAny()) {
        return new AnyVersionConstraint();
    }
    if ($constraint->getMinor()
        ->isAny()) {
        return new SpecificMajorVersionConstraint($constraint->getVersionString(), $constraint->getMajor()
            ->getValue() ?? 0);
    }
    if ($constraint->getPatch()
        ->isAny()) {
        return new SpecificMajorAndMinorVersionConstraint($constraint->getVersionString(), $constraint->getMajor()
            ->getValue() ?? 0, $constraint->getMinor()
            ->getValue() ?? 0);
    }
    return new ExactVersionConstraint($constraint->getVersionString());
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal