1
0
Fork 0

Fix handling of virtual packages when searching for packages or when looking up the preferred version (init & require command), refs #10489

pull/10541/head
Jordi Boggiano 2022-02-16 15:44:43 +01:00
parent 8b5254688c
commit 2a2440c2a1
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 41 additions and 16 deletions

View File

@ -577,7 +577,21 @@ EOT
} }
$matches = array_values($matches); $matches = array_values($matches);
$exactMatch = null; $exactMatch = false;
foreach ($matches as $match) {
if ($match['name'] === $package) {
$exactMatch = true;
break;
}
}
// no match, prompt which to pick
if (!$exactMatch) {
$providers = $this->getRepos()->getProviders($package);
if (count($providers) > 0) {
array_unshift($matches, array('name' => $package, 'description' => ''));
}
$choices = array(); $choices = array();
foreach ($matches as $position => $foundPackage) { foreach ($matches as $position => $foundPackage) {
$abandoned = ''; $abandoned = '';
@ -591,14 +605,8 @@ EOT
} }
$choices[] = sprintf(' <info>%5s</info> %s %s', "[$position]", $foundPackage['name'], $abandoned); $choices[] = sprintf(' <info>%5s</info> %s %s', "[$position]", $foundPackage['name'], $abandoned);
if ($foundPackage['name'] === $package) {
$exactMatch = true;
break;
}
} }
// no match, prompt which to pick
if (!$exactMatch) {
$io->writeError(array( $io->writeError(array(
'', '',
sprintf('Found <info>%s</info> packages matching <info>%s</info>', count($matches), $package), sprintf('Found <info>%s</info> packages matching <info>%s</info>', count($matches), $package),
@ -893,7 +901,8 @@ EOT
$platformRequirementFilter = PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs); $platformRequirementFilter = PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs);
// find the latest version allowed in this repo set // find the latest version allowed in this repo set
$versionSelector = new VersionSelector($this->getRepositorySet($input, $minimumStability), $platformRepo); $repoSet = $this->getRepositorySet($input, $minimumStability);
$versionSelector = new VersionSelector($repoSet, $platformRepo);
$effectiveMinimumStability = $minimumStability ?: $this->getMinimumStability($input); $effectiveMinimumStability = $minimumStability ?: $this->getMinimumStability($input);
$package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $platformRequirementFilter); $package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $platformRequirementFilter);
@ -905,6 +914,22 @@ EOT
return array($name, $requiredVersion ?: '*'); return array($name, $requiredVersion ?: '*');
} }
// Check if it is a virtual package provided by others
$providers = $repoSet->getProviders($name);
if (count($providers) > 0) {
$constraint = '*';
if ($input->isInteractive()) {
$constraint = $this->getIO()->askAndValidate('Package "<info>'.$name.'</info>" does not exist but is provided by '.count($providers).' packages. Which version constraint would you like to use? [<info>*</info>] ', function ($value) {
$parser = new VersionParser();
$parser->parseConstraints($value);
return $value;
}, 3, '*');
}
return array($name, $constraint);
}
// Check whether the package requirements were the problem // Check whether the package requirements were the problem
if (!($platformRequirementFilter instanceof IgnoreAllPlatformRequirementFilter) && ($candidate = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, PlatformRequirementFilterFactory::ignoreAll()))) { if (!($platformRequirementFilter instanceof IgnoreAllPlatformRequirementFilter) && ($candidate = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, PlatformRequirementFilterFactory::ignoreAll()))) {
throw new \InvalidArgumentException(sprintf( throw new \InvalidArgumentException(sprintf(