function UpdateCommand::getPackagesInteractively
Parameters
array<string> $packages:
Return value
array<string>
1 call to UpdateCommand::getPackagesInteractively()
- UpdateCommand::execute in vendor/
composer/ composer/ src/ Composer/ Command/ UpdateCommand.php - Executes the current command.
File
-
vendor/
composer/ composer/ src/ Composer/ Command/ UpdateCommand.php, line 309
Class
- UpdateCommand
- @author Jordi Boggiano <j.boggiano@seld.be> @author Nils Adermann <naderman@naderman.de>
Namespace
Composer\CommandCode
private function getPackagesInteractively(IOInterface $io, InputInterface $input, OutputInterface $output, Composer $composer, array $packages) : array {
if (!$input->isInteractive()) {
throw new \InvalidArgumentException('--interactive cannot be used in non-interactive terminals.');
}
$platformReqFilter = $this->getPlatformRequirementFilter($input);
$stabilityFlags = $composer->getPackage()
->getStabilityFlags();
$requires = array_merge($composer->getPackage()
->getRequires(), $composer->getPackage()
->getDevRequires());
$filter = \count($packages) > 0 ? BasePackage::packageNamesToRegexp($packages) : null;
$io->writeError('<info>Loading packages that can be updated...</info>');
$autocompleterValues = [];
$installedPackages = $composer->getLocker()
->isLocked() ? $composer->getLocker()
->getLockedRepository(true)
->getPackages() : $composer->getRepositoryManager()
->getLocalRepository()
->getPackages();
$versionSelector = $this->createVersionSelector($composer);
foreach ($installedPackages as $package) {
if ($filter !== null && !Preg::isMatch($filter, $package->getName())) {
continue;
}
$currentVersion = $package->getPrettyVersion();
$constraint = isset($requires[$package->getName()]) ? $requires[$package->getName()]
->getPrettyConstraint() : null;
$stability = isset($stabilityFlags[$package->getName()]) ? (string) array_search($stabilityFlags[$package->getName()], BasePackage::STABILITIES, true) : $composer->getPackage()
->getMinimumStability();
$latestVersion = $versionSelector->findBestCandidate($package->getName(), $constraint, $stability, $platformReqFilter);
if ($latestVersion !== false && ($package->getVersion() !== $latestVersion->getVersion() || $latestVersion->isDev())) {
$autocompleterValues[$package->getName()] = '<comment>' . $currentVersion . '</comment> => <comment>' . $latestVersion->getPrettyVersion() . '</comment>';
}
}
if (0 === \count($installedPackages)) {
foreach ($requires as $req => $constraint) {
if (PlatformRepository::isPlatformPackage($req)) {
continue;
}
$autocompleterValues[$req] = '';
}
}
if (0 === \count($autocompleterValues)) {
throw new \RuntimeException('Could not find any package with new versions available');
}
$packages = $io->select('Select packages: (Select more than one value separated by comma) ', $autocompleterValues, false, 1, 'No package named "%s" is installed.', true);
$table = new Table($output);
$table->setHeaders([
'Selected packages',
]);
foreach ($packages as $package) {
$table->addRow([
$package,
]);
}
$table->render();
if ($io->askConfirmation(sprintf('Would you like to continue and update the above package%s [<comment>yes</comment>]? ', 1 === count($packages) ? '' : 's'))) {
return $packages;
}
throw new \RuntimeException('Installation aborted.');
}