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
Namespace
PharIo\VersionCode
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());
}