diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index dc33f6457..e2361e226 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -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 %s for %s', @@ -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 diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 3d74a1f2b..2eefac029 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -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';