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

Breadcrumb

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

function RequireCommand::updateRequirementsAfterResolution

Parameters

list<string> $requirementsToUpdate:

1 call to RequireCommand::updateRequirementsAfterResolution()
RequireCommand::execute in vendor/composer/composer/src/Composer/Command/RequireCommand.php

File

vendor/composer/composer/src/Composer/Command/RequireCommand.php, line 517

Class

RequireCommand
@author Jérémy Romey <jeremy@free-agent.fr> @author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\Command

Code

private function updateRequirementsAfterResolution(array $requirementsToUpdate, string $requireKey, string $removeKey, bool $sortPackages, bool $dryRun, bool $fixed) : int {
    $composer = $this->requireComposer();
    $locker = $composer->getLocker();
    $requirements = [];
    $versionSelector = new VersionSelector(new RepositorySet());
    $repo = $locker->isLocked() ? $composer->getLocker()
        ->getLockedRepository(true) : $composer->getRepositoryManager()
        ->getLocalRepository();
    foreach ($requirementsToUpdate as $packageName) {
        $package = $repo->findPackage($packageName, '*');
        while ($package instanceof AliasPackage) {
            $package = $package->getAliasOf();
        }
        if (!$package instanceof PackageInterface) {
            continue;
        }
        if ($fixed) {
            $requirements[$packageName] = $package->getPrettyVersion();
        }
        else {
            $requirements[$packageName] = $versionSelector->findRecommendedRequireVersion($package);
        }
        $this->getIO()
            ->writeError(sprintf('Using version <info>%s</info> for <info>%s</info>', $requirements[$packageName], $packageName));
        if (Preg::isMatch('{^dev-(?!main$|master$|trunk$|latest$)}', $requirements[$packageName])) {
            $this->getIO()
                ->warning('Version ' . $requirements[$packageName] . ' looks like it may be a feature branch which is unlikely to keep working in the long run and may be in an unstable state');
            if ($this->getIO()
                ->isInteractive() && !$this->getIO()
                ->askConfirmation('Are you sure you want to use this constraint (<comment>Y</comment>) or would you rather abort (<comment>n</comment>) the whole operation [<comment>Y,n</comment>]? ')) {
                $this->revertComposerFile();
                return 1;
            }
        }
    }
    if (!$dryRun) {
        $this->updateFile($this->json, $requirements, $requireKey, $removeKey, $sortPackages);
        if ($locker->isLocked() && $composer->getConfig()
            ->get('lock')) {
            $stabilityFlags = RootPackageLoader::extractStabilityFlags($requirements, $composer->getPackage()
                ->getMinimumStability(), []);
            $locker->updateHash($this->json, function (array $lockData) use ($stabilityFlags) {
                foreach ($stabilityFlags as $packageName => $flag) {
                    $lockData['stability-flags'][$packageName] = $flag;
                }
                return $lockData;
            });
        }
    }
    return 0;
}

API Navigation

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