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

Breadcrumb

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

function ShowCommand::findLatestPackage

Given a package, this finds the latest package matching it

1 call to ShowCommand::findLatestPackage()
ShowCommand::execute in vendor/composer/composer/src/Composer/Command/ShowCommand.php
Executes the current command.

File

vendor/composer/composer/src/Composer/Command/ShowCommand.php, line 1460

Class

ShowCommand
@author Robert Schönthal <seroscho@googlemail.com> @author Jordi Boggiano <j.boggiano@seld.be> @author Jérémy Romey <jeremyFreeAgent> @author Mihai Plasoianu <mihai@plasoianu.de>

Namespace

Composer\Command

Code

private function findLatestPackage(PackageInterface $package, Composer $composer, PlatformRepository $platformRepo, bool $majorOnly, bool $minorOnly, bool $patchOnly, PlatformRequirementFilterInterface $platformReqFilter) : ?PackageInterface {
    // find the latest version allowed in this repo set
    $name = $package->getName();
    $versionSelector = new VersionSelector($this->getRepositorySet($composer), $platformRepo);
    $stability = $composer->getPackage()
        ->getMinimumStability();
    $flags = $composer->getPackage()
        ->getStabilityFlags();
    if (isset($flags[$name])) {
        $stability = array_search($flags[$name], BasePackage::STABILITIES, true);
    }
    $bestStability = $stability;
    if ($composer->getPackage()
        ->getPreferStable()) {
        $bestStability = $package->getStability();
    }
    $targetVersion = null;
    if (0 === strpos($package->getVersion(), 'dev-')) {
        $targetVersion = $package->getVersion();
        // dev-x branches are considered to be on the latest major version always, do not look up for a new commit as that is deemed a minor upgrade (albeit risky)
        if ($majorOnly) {
            return null;
        }
    }
    if ($targetVersion === null) {
        if ($majorOnly && Preg::isMatch('{^(?P<zero_major>(?:0\\.)+)?(?P<first_meaningful>\\d+)\\.}', $package->getVersion(), $match)) {
            $targetVersion = '>=' . $match['zero_major'] . ((int) $match['first_meaningful'] + 1) . ',<9999999-dev';
        }
        if ($minorOnly) {
            $targetVersion = '^' . $package->getVersion();
        }
        if ($patchOnly) {
            $trimmedVersion = Preg::replace('{(\\.0)+$}D', '', $package->getVersion());
            $partsNeeded = substr($trimmedVersion, 0, 1) === '0' ? 4 : 3;
            while (substr_count($trimmedVersion, '.') + 1 < $partsNeeded) {
                $trimmedVersion .= '.0';
            }
            $targetVersion = '~' . $trimmedVersion;
        }
    }
    if ($this->getIO()
        ->isVerbose()) {
        $showWarnings = true;
    }
    else {
        $showWarnings = static function (PackageInterface $candidate) use ($package) : bool {
            if (str_starts_with($candidate->getVersion(), 'dev-') || str_starts_with($package->getVersion(), 'dev-')) {
                return false;
            }
            return version_compare($candidate->getVersion(), $package->getVersion(), '<=');
        };
    }
    $candidate = $versionSelector->findBestCandidate($name, $targetVersion, $bestStability, $platformReqFilter, 0, $this->getIO(), $showWarnings);
    while ($candidate instanceof AliasPackage) {
        $candidate = $candidate->getAliasOf();
    }
    return $candidate !== false ? $candidate : null;
}

API Navigation

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