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

Breadcrumb

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

function VersionParser::parseConstraints

Same name in this branch
  1. 11.1.x vendor/composer/composer/src/Composer/Package/Version/VersionParser.php \Composer\Package\Version\VersionParser::parseConstraints()

Parses a constraint string into MultiConstraint and/or Constraint objects.

Parameters

string $constraints:

Return value

ConstraintInterface

2 calls to VersionParser::parseConstraints()
VersionParser::parseConstraints in vendor/composer/composer/src/Composer/Package/Version/VersionParser.php
@inheritDoc
VersionParser::parseConstraints in vendor/composer/composer/src/Composer/Package/Version/VersionParser.php
@inheritDoc
1 method overrides VersionParser::parseConstraints()
VersionParser::parseConstraints in vendor/composer/composer/src/Composer/Package/Version/VersionParser.php
@inheritDoc

File

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

Class

VersionParser
Version parser.

Namespace

Composer\Semver

Code

public function parseConstraints($constraints) {
    $prettyConstraint = (string) $constraints;
    $orConstraints = preg_split('{\\s*\\|\\|?\\s*}', trim((string) $constraints));
    if (false === $orConstraints) {
        throw new \RuntimeException('Failed to preg_split string: ' . $constraints);
    }
    $orGroups = array();
    foreach ($orConstraints as $orConstraint) {
        $andConstraints = preg_split('{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}', $orConstraint);
        if (false === $andConstraints) {
            throw new \RuntimeException('Failed to preg_split string: ' . $orConstraint);
        }
        if (\count($andConstraints) > 1) {
            $constraintObjects = array();
            foreach ($andConstraints as $andConstraint) {
                foreach ($this->parseConstraint($andConstraint) as $parsedAndConstraint) {
                    $constraintObjects[] = $parsedAndConstraint;
                }
            }
        }
        else {
            $constraintObjects = $this->parseConstraint($andConstraints[0]);
        }
        if (1 === \count($constraintObjects)) {
            $constraint = $constraintObjects[0];
        }
        else {
            $constraint = new MultiConstraint($constraintObjects);
        }
        $orGroups[] = $constraint;
    }
    $parsedConstraint = MultiConstraint::create($orGroups, false);
    $parsedConstraint->setPrettyString($prettyConstraint);
    return $parsedConstraint;
}

API Navigation

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