1
0
Fork 0

Hide not-yet installed packages from "require" and "init" suggestions

pull/8372/head
xy2z 2019-11-12 16:32:04 +01:00
parent 1a0d5dfacd
commit a91c946e27
1 changed files with 29 additions and 0 deletions

View File

@ -436,11 +436,40 @@ EOT
} }
$versionParser = new VersionParser(); $versionParser = new VersionParser();
$composer = $this->getComposer(false);
$installedRepo = ($composer) ? $composer->getRepositoryManager()->getLocalRepository() : null;
$io = $this->getIO(); $io = $this->getIO();
while (null !== $package = $io->ask('Search for a package: ')) { while (null !== $package = $io->ask('Search for a package: ')) {
$matches = $this->findPackages($package); $matches = $this->findPackages($package);
if (count($matches)) { if (count($matches)) {
// Exclude existing packages
$existingPackages = [];
foreach ($matches as $position => $foundPackage) {
if ($installedRepo && $installedRepo->findPackage($foundPackage['name'], '*')) {
$existingPackages[] = $position;
continue;
}
foreach ($requires as $requiredPackage) {
$existingPackageName = substr($requiredPackage, 0, strpos($requiredPackage, ' '));
if ($foundPackage['name'] == $existingPackageName) {
$existingPackages[] = $position;
break;
}
}
}
// Remove existing packages from search results.
if (!empty($existingPackages)) {
foreach ($existingPackages as $position) {
unset($matches[$position]);
}
$matches = array_values($matches);
}
$exactMatch = null; $exactMatch = null;
$choices = array(); $choices = array();
foreach ($matches as $position => $foundPackage) { foreach ($matches as $position => $foundPackage) {