1
0
Fork 0

Make use of prefer-stable/minimum-stability when picking versions in require command, fixes #6219

pull/6213/merge
Jordi Boggiano 2017-03-06 18:39:44 +01:00
parent 7d5d884669
commit 586f4bac87
2 changed files with 13 additions and 6 deletions

View File

@ -352,7 +352,7 @@ EOT
return $this->repos;
}
protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array(), $phpVersion = null)
protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array(), $phpVersion = null, $preferredStability = 'stable')
{
if ($requires) {
$requires = $this->normalizeRequirements($requires);
@ -362,7 +362,7 @@ EOT
foreach ($requires as $requirement) {
if (!isset($requirement['version'])) {
// determine the best version automatically
$version = $this->findBestVersionForPackage($input, $requirement['name'], $phpVersion);
$version = $this->findBestVersionForPackage($input, $requirement['name'], $phpVersion, $preferredStability);
$requirement['version'] = $version;
$io->writeError(sprintf(
@ -457,7 +457,7 @@ EOT
);
if (false === $constraint) {
$constraint = $this->findBestVersionForPackage($input, $package, $phpVersion);
$constraint = $this->findBestVersionForPackage($input, $package, $phpVersion, $preferredStability);
$io->writeError(sprintf(
'Using version <info>%s</info> for <info>%s</info>',
@ -623,14 +623,15 @@ EOT
* @param InputInterface $input
* @param string $name
* @param string $phpVersion
* @param string $preferredStability
* @throws \InvalidArgumentException
* @return string
*/
private function findBestVersionForPackage(InputInterface $input, $name, $phpVersion)
private function findBestVersionForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable')
{
// find the latest version allowed in this pool
$versionSelector = new VersionSelector($this->getPool($input));
$package = $versionSelector->findBestCandidate($name, null, $phpVersion);
$package = $versionSelector->findBestCandidate($name, null, $phpVersion, $preferredStability);
if (!$package) {
// Check whether the PHP version was the problem

View File

@ -107,8 +107,14 @@ EOT
$repos
));
if ($composer->getPackage()->getPreferStable()) {
$preferredStability = 'stable';
} else {
$preferredStability = $composer->getPackage()->getMinimumStability();
}
$phpVersion = $this->repos->findPackage('php', '*')->getVersion();
$requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'), $phpVersion);
$requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'), $phpVersion, $preferredStability);
$requireKey = $input->getOption('dev') ? 'require-dev' : 'require';
$removeKey = $input->getOption('dev') ? 'require' : 'require-dev';