1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 17:12:51 +00:00

Refactor some common logic in Command classes

This commit is contained in:
Fabien Potencier 2016-10-30 14:29:47 -07:00
parent 8cf9733001
commit 69740bbbee
4 changed files with 40 additions and 75 deletions

View file

@ -111,7 +111,7 @@ EOT
$config = Factory::createConfig();
$io = $this->getIO();
$this->updatePreferredOptions($config, $input, $preferSource, $preferDist, true);
list($preferSource, $preferDist) = $this->getPreferredInstallOptions($config, $input, true);
if ($input->getOption('dev')) {
$io->writeError('<warning>You are using the deprecated option "dev". Dev packages are installed by default now.</warning>');
@ -168,8 +168,7 @@ EOT
$composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ROOT_PACKAGE_INSTALL, $installDevPackages);
}
$rootPackageConfig = $composer->getConfig();
$this->updatePreferredOptions($rootPackageConfig, $input, $preferSource, $preferDist);
list($preferSource, $preferDist) = $this->getPreferredInstallOptions($composer->getConfig(), $input);
// install dependencies of the created project
if ($noInstall === false) {
@ -371,36 +370,4 @@ EOT
{
return new InstallationManager();
}
/**
* Updated preferSource or preferDist based on the preferredInstall config option
* @param Config $config
* @param InputInterface $input
* @param bool $preferSource
* @param bool $preferDist
* @param bool $keepVcsRequiresPreferSource
*/
protected function updatePreferredOptions(Config $config, InputInterface $input, &$preferSource, &$preferDist, $keepVcsRequiresPreferSource = false)
{
$preferSource = false;
$preferDist = false;
switch ($config->get('preferred-install')) {
case 'source':
$preferSource = true;
break;
case 'dist':
$preferDist = true;
break;
case 'auto':
default:
// noop
break;
}
if ($input->getOption('prefer-source') || $input->getOption('prefer-dist') || ($keepVcsRequiresPreferSource && $input->getOption('keep-vcs'))) {
$preferSource = $input->getOption('prefer-source') || ($keepVcsRequiresPreferSource && $input->getOption('keep-vcs'));
$preferDist = $input->getOption('prefer-dist');
}
}
}