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

Breadcrumb

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

class VersionParser

Same name in this branch
  1. 11.1.x vendor/composer/semver/src/VersionParser.php \Composer\Semver\VersionParser

Hierarchy

  • class \Composer\Semver\VersionParser
    • class \Composer\Package\Version\VersionParser extends \Composer\Semver\VersionParser

Expanded class hierarchy of VersionParser

34 files declare their use of VersionParser
AliasPackage.php in vendor/composer/composer/src/Composer/Package/AliasPackage.php
ArchiveCommand.php in vendor/composer/composer/src/Composer/Command/ArchiveCommand.php
ArrayLoader.php in vendor/composer/composer/src/Composer/Package/Loader/ArrayLoader.php
ArrayRepository.php in vendor/composer/composer/src/Composer/Repository/ArrayRepository.php
BaseCommand.php in vendor/composer/composer/src/Composer/Command/BaseCommand.php

... See full list

File

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

Namespace

Composer\Package\Version
View source
class VersionParser extends SemverVersionParser {
    public const DEFAULT_BRANCH_ALIAS = '9999999-dev';
    
    /** @var array<string, ConstraintInterface> Constraint parsing cache */
    private static $constraints = [];
    
    /**
     * @inheritDoc
     */
    public function parseConstraints($constraints) : ConstraintInterface {
        if (!isset(self::$constraints[$constraints])) {
            self::$constraints[$constraints] = parent::parseConstraints($constraints);
        }
        return self::$constraints[$constraints];
    }
    
    /**
     * 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.
     *
     * @param string[] $pairs a set of package/version pairs separated by ":", "=" or " "
     *
     * @return list<array{name: string, version?: string}>
     */
    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;
    }
    public static function isUpgrade(string $normalizedFrom, string $normalizedTo) : bool {
        if ($normalizedFrom === $normalizedTo) {
            return true;
        }
        if (in_array($normalizedFrom, [
            'dev-master',
            'dev-trunk',
            'dev-default',
        ], true)) {
            $normalizedFrom = VersionParser::DEFAULT_BRANCH_ALIAS;
        }
        if (in_array($normalizedTo, [
            'dev-master',
            'dev-trunk',
            'dev-default',
        ], true)) {
            $normalizedTo = VersionParser::DEFAULT_BRANCH_ALIAS;
        }
        if (strpos($normalizedFrom, 'dev-') === 0 || strpos($normalizedTo, 'dev-') === 0) {
            return true;
        }
        $sorted = Semver::sort([
            $normalizedTo,
            $normalizedFrom,
        ]);
        return $sorted[0] === $normalizedFrom;
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title
VersionParser::$constraints private static property @var array&lt;string, ConstraintInterface&gt; Constraint parsing cache
VersionParser::$modifierRegex private static property Regex to match pre-release data (sort of).
VersionParser::$stabilitiesRegex private static property @var string
VersionParser::DEFAULT_BRANCH_ALIAS public constant
VersionParser::expandStability private function Expand shorthand stability string to long version.
VersionParser::isUpgrade public static function
VersionParser::manipulateVersionString private function Increment, decrement, or simply pad a version number.
VersionParser::normalize public function Normalizes a version string to be able to perform comparisons on it.
VersionParser::normalizeBranch public function Normalizes a branch name to be able to perform comparisons on it.
VersionParser::normalizeDefaultBranch Deprecated public function Normalizes a default branch name (i.e. master on git) to 9999999-dev.
VersionParser::normalizeStability public static function @phpstan-return &#039;stable&#039;|&#039;RC&#039;|&#039;beta&#039;|&#039;alpha&#039;|&#039;dev&#039;
VersionParser::parseConstraint private function @phpstan-return non-empty-array&lt;ConstraintInterface&gt;
VersionParser::parseConstraints public function @inheritDoc Overrides VersionParser::parseConstraints
VersionParser::parseNameVersionPairs public function Parses an array of strings representing package/version pairs.
VersionParser::parseNumericAliasPrefix public function Extract numeric prefix from alias, if it is in numeric format, suitable for version comparison.
VersionParser::parseStability public static function Returns the stability of a version.

API Navigation

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