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

Breadcrumb

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

function RequireCommand::doUpdate

Parameters

array<string, string> $requirements:

'require'|'require-dev' $requireKey:

'require'|'require-dev' $removeKey:

Throws

\Exception

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

File

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

Class

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

Namespace

Composer\Command

Code

private function doUpdate(InputInterface $input, OutputInterface $output, IOInterface $io, array $requirements, string $requireKey, string $removeKey) : int {
    // Update packages
    $this->resetComposer();
    $composer = $this->requireComposer();
    $this->dependencyResolutionCompleted = false;
    $composer->getEventDispatcher()
        ->addListener(InstallerEvents::PRE_OPERATIONS_EXEC, function () : void {
        $this->dependencyResolutionCompleted = true;
    }, 10000);
    if ($input->getOption('dry-run')) {
        $rootPackage = $composer->getPackage();
        $links = [
            'require' => $rootPackage->getRequires(),
            'require-dev' => $rootPackage->getDevRequires(),
        ];
        $loader = new ArrayLoader();
        $newLinks = $loader->parseLinks($rootPackage->getName(), $rootPackage->getPrettyVersion(), BasePackage::$supportedLinkTypes[$requireKey]['method'], $requirements);
        $links[$requireKey] = array_merge($links[$requireKey], $newLinks);
        foreach ($requirements as $package => $constraint) {
            unset($links[$removeKey][$package]);
        }
        $rootPackage->setRequires($links['require']);
        $rootPackage->setDevRequires($links['require-dev']);
        // extract stability flags & references as they weren't present when loading the unmodified composer.json
        $references = $rootPackage->getReferences();
        $references = RootPackageLoader::extractReferences($requirements, $references);
        $rootPackage->setReferences($references);
        $stabilityFlags = $rootPackage->getStabilityFlags();
        $stabilityFlags = RootPackageLoader::extractStabilityFlags($requirements, $rootPackage->getMinimumStability(), $stabilityFlags);
        $rootPackage->setStabilityFlags($stabilityFlags);
        unset($stabilityFlags, $references);
    }
    $updateDevMode = !$input->getOption('update-no-dev');
    $optimize = $input->getOption('optimize-autoloader') || $composer->getConfig()
        ->get('optimize-autoloader');
    $authoritative = $input->getOption('classmap-authoritative') || $composer->getConfig()
        ->get('classmap-authoritative');
    $apcuPrefix = $input->getOption('apcu-autoloader-prefix');
    $apcu = $apcuPrefix !== null || $input->getOption('apcu-autoloader') || $composer->getConfig()
        ->get('apcu-autoloader');
    $updateAllowTransitiveDependencies = Request::UPDATE_ONLY_LISTED;
    $flags = '';
    if ($input->getOption('update-with-all-dependencies') || $input->getOption('with-all-dependencies')) {
        $updateAllowTransitiveDependencies = Request::UPDATE_LISTED_WITH_TRANSITIVE_DEPS;
        $flags .= ' --with-all-dependencies';
    }
    elseif ($input->getOption('update-with-dependencies') || $input->getOption('with-dependencies')) {
        $updateAllowTransitiveDependencies = Request::UPDATE_LISTED_WITH_TRANSITIVE_DEPS_NO_ROOT_REQUIRE;
        $flags .= ' --with-dependencies';
    }
    $io->writeError('<info>Running composer update ' . implode(' ', array_keys($requirements)) . $flags . '</info>');
    $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'require', $input, $output);
    $composer->getEventDispatcher()
        ->dispatch($commandEvent->getName(), $commandEvent);
    $composer->getInstallationManager()
        ->setOutputProgress(!$input->getOption('no-progress'));
    $install = Installer::create($io, $composer);
    [
        $preferSource,
        $preferDist,
    ] = $this->getPreferredInstallOptions($composer->getConfig(), $input);
    $install->setDryRun($input->getOption('dry-run'))
        ->setVerbose($input->getOption('verbose'))
        ->setPreferSource($preferSource)
        ->setPreferDist($preferDist)
        ->setDevMode($updateDevMode)
        ->setOptimizeAutoloader($optimize)
        ->setClassMapAuthoritative($authoritative)
        ->setApcuAutoloader($apcu, $apcuPrefix)
        ->setUpdate(true)
        ->setInstall(!$input->getOption('no-install'))
        ->setUpdateAllowTransitiveDependencies($updateAllowTransitiveDependencies)
        ->setPlatformRequirementFilter($this->getPlatformRequirementFilter($input))
        ->setPreferStable($input->getOption('prefer-stable'))
        ->setPreferLowest($input->getOption('prefer-lowest'))
        ->setAudit(!$input->getOption('no-audit'))
        ->setAuditFormat($this->getAuditFormat($input))
        ->setMinimalUpdate($input->getOption('minimal-changes'));
    // if no lock is present, or the file is brand new, we do not do a
    // partial update as this is not supported by the Installer
    if (!$this->firstRequire && $composer->getLocker()
        ->isLocked()) {
        $install->setUpdateAllowList(array_keys($requirements));
    }
    $status = $install->run();
    if ($status !== 0 && $status !== Installer::ERROR_AUDIT_FAILED) {
        if ($status === Installer::ERROR_DEPENDENCY_RESOLUTION_FAILED) {
            foreach ($this->normalizeRequirements($input->getArgument('packages')) as $req) {
                if (!isset($req['version'])) {
                    $io->writeError('You can also try re-running composer require with an explicit version constraint, e.g. "composer require ' . $req['name'] . ':*" to figure out if any version is installable, or "composer require ' . $req['name'] . ':^2.1" if you know which you need.');
                    break;
                }
            }
        }
        $this->revertComposerFile();
    }
    return $status;
}
RSS feed
Powered by Drupal