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

Breadcrumb

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

function VersionParser::parseNameVersionPairs

Parses an array of strings representing package/version pairs.

The parsing results in an array of arrays, each of which contain a 'name' key with value and optionally a 'version' key with value.

Parameters

string[] $pairs a set of package/version pairs separated by ":", "=" or " ":

Return value

list<array{name: string, version?: string}>

File

vendor/composer/composer/src/Composer/Package/Version/VersionParser.php, line 50

Class

VersionParser

Namespace

Composer\Package\Version

Code

public function parseNameVersionPairs(array $pairs) : array {
    $pairs = array_values($pairs);
    $result = [];
    for ($i = 0, $count = count($pairs); $i < $count; $i++) {
        $pair = Preg::replace('{^([^=: ]+)[=: ](.*)$}', '$1 $2', trim($pairs[$i]));
        if (false === strpos($pair, ' ') && isset($pairs[$i + 1]) && false === strpos($pairs[$i + 1], '/') && !Preg::isMatch('{(?<=[a-z0-9_/-])\\*|\\*(?=[a-z0-9_/-])}i', $pairs[$i + 1]) && !PlatformRepository::isPlatformPackage($pairs[$i + 1])) {
            $pair .= ' ' . $pairs[$i + 1];
            $i++;
        }
        if (strpos($pair, ' ')) {
            [
                $name,
                $version,
            ] = explode(' ', $pair, 2);
            $result[] = [
                'name' => $name,
                'version' => $version,
            ];
        }
        else {
            $result[] = [
                'name' => $pair,
            ];
        }
    }
    return $result;
}

API Navigation

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