Make use of prefer-stable/minimum-stability when picking versions in require command, fixes #6219
parent
7d5d884669
commit
586f4bac87
|
@ -352,7 +352,7 @@ EOT
|
||||||
return $this->repos;
|
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) {
|
if ($requires) {
|
||||||
$requires = $this->normalizeRequirements($requires);
|
$requires = $this->normalizeRequirements($requires);
|
||||||
|
@ -362,7 +362,7 @@ EOT
|
||||||
foreach ($requires as $requirement) {
|
foreach ($requires as $requirement) {
|
||||||
if (!isset($requirement['version'])) {
|
if (!isset($requirement['version'])) {
|
||||||
// determine the best version automatically
|
// determine the best version automatically
|
||||||
$version = $this->findBestVersionForPackage($input, $requirement['name'], $phpVersion);
|
$version = $this->findBestVersionForPackage($input, $requirement['name'], $phpVersion, $preferredStability);
|
||||||
$requirement['version'] = $version;
|
$requirement['version'] = $version;
|
||||||
|
|
||||||
$io->writeError(sprintf(
|
$io->writeError(sprintf(
|
||||||
|
@ -457,7 +457,7 @@ EOT
|
||||||
);
|
);
|
||||||
|
|
||||||
if (false === $constraint) {
|
if (false === $constraint) {
|
||||||
$constraint = $this->findBestVersionForPackage($input, $package, $phpVersion);
|
$constraint = $this->findBestVersionForPackage($input, $package, $phpVersion, $preferredStability);
|
||||||
|
|
||||||
$io->writeError(sprintf(
|
$io->writeError(sprintf(
|
||||||
'Using version <info>%s</info> for <info>%s</info>',
|
'Using version <info>%s</info> for <info>%s</info>',
|
||||||
|
@ -623,14 +623,15 @@ EOT
|
||||||
* @param InputInterface $input
|
* @param InputInterface $input
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $phpVersion
|
* @param string $phpVersion
|
||||||
|
* @param string $preferredStability
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* @return string
|
* @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
|
// find the latest version allowed in this pool
|
||||||
$versionSelector = new VersionSelector($this->getPool($input));
|
$versionSelector = new VersionSelector($this->getPool($input));
|
||||||
$package = $versionSelector->findBestCandidate($name, null, $phpVersion);
|
$package = $versionSelector->findBestCandidate($name, null, $phpVersion, $preferredStability);
|
||||||
|
|
||||||
if (!$package) {
|
if (!$package) {
|
||||||
// Check whether the PHP version was the problem
|
// Check whether the PHP version was the problem
|
||||||
|
|
|
@ -107,8 +107,14 @@ EOT
|
||||||
$repos
|
$repos
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if ($composer->getPackage()->getPreferStable()) {
|
||||||
|
$preferredStability = 'stable';
|
||||||
|
} else {
|
||||||
|
$preferredStability = $composer->getPackage()->getMinimumStability();
|
||||||
|
}
|
||||||
|
|
||||||
$phpVersion = $this->repos->findPackage('php', '*')->getVersion();
|
$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';
|
$requireKey = $input->getOption('dev') ? 'require-dev' : 'require';
|
||||||
$removeKey = $input->getOption('dev') ? 'require' : 'require-dev';
|
$removeKey = $input->getOption('dev') ? 'require' : 'require-dev';
|
||||||
|
|
Loading…
Reference in New Issue