Merge pull request #5830 from fabpot/logic-refactoring
Refactor some common logic in Command classespull/5840/merge
commit
f7475c6ff6
|
@ -13,6 +13,7 @@
|
||||||
namespace Composer\Command;
|
namespace Composer\Command;
|
||||||
|
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
|
use Composer\Config;
|
||||||
use Composer\Console\Application;
|
use Composer\Console\Application;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\IO\NullIO;
|
use Composer\IO\NullIO;
|
||||||
|
@ -128,4 +129,39 @@ abstract class BaseCommand extends Command
|
||||||
|
|
||||||
parent::initialize($input, $output);
|
parent::initialize($input, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns preferSource and preferDist values based on the configuration.
|
||||||
|
*
|
||||||
|
* @param Config $config
|
||||||
|
* @param InputInterface $input
|
||||||
|
* @param bool $keepVcsRequiresPreferSource
|
||||||
|
*
|
||||||
|
* @return bool[] An array composed of the preferSource and preferDist values
|
||||||
|
*/
|
||||||
|
protected function getPreferredInstallOptions(Config $config, InputInterface $input, $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->hasOption('keep-vcs') && $input->getOption('keep-vcs'))) {
|
||||||
|
$preferSource = $input->getOption('prefer-source') || ($keepVcsRequiresPreferSource && $input->hasOption('keep-vcs') && $input->getOption('keep-vcs'));
|
||||||
|
$preferDist = $input->getOption('prefer-dist');
|
||||||
|
}
|
||||||
|
|
||||||
|
return array($preferSource, $preferDist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ EOT
|
||||||
$config = Factory::createConfig();
|
$config = Factory::createConfig();
|
||||||
$io = $this->getIO();
|
$io = $this->getIO();
|
||||||
|
|
||||||
$this->updatePreferredOptions($config, $input, $preferSource, $preferDist, true);
|
list($preferSource, $preferDist) = $this->getPreferredInstallOptions($config, $input, true);
|
||||||
|
|
||||||
if ($input->getOption('dev')) {
|
if ($input->getOption('dev')) {
|
||||||
$io->writeError('<warning>You are using the deprecated option "dev". Dev packages are installed by default now.</warning>');
|
$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);
|
$composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ROOT_PACKAGE_INSTALL, $installDevPackages);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rootPackageConfig = $composer->getConfig();
|
list($preferSource, $preferDist) = $this->getPreferredInstallOptions($composer->getConfig(), $input);
|
||||||
$this->updatePreferredOptions($rootPackageConfig, $input, $preferSource, $preferDist);
|
|
||||||
|
|
||||||
// install dependencies of the created project
|
// install dependencies of the created project
|
||||||
if ($noInstall === false) {
|
if ($noInstall === false) {
|
||||||
|
@ -371,36 +370,4 @@ EOT
|
||||||
{
|
{
|
||||||
return new InstallationManager();
|
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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,27 +89,8 @@ EOT
|
||||||
|
|
||||||
$install = Installer::create($io, $composer);
|
$install = Installer::create($io, $composer);
|
||||||
|
|
||||||
$preferSource = false;
|
|
||||||
$preferDist = false;
|
|
||||||
|
|
||||||
$config = $composer->getConfig();
|
$config = $composer->getConfig();
|
||||||
|
list($preferSource, $preferDist) = $this->getPreferredInstallOptions($config, $input);
|
||||||
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')) {
|
|
||||||
$preferSource = $input->getOption('prefer-source');
|
|
||||||
$preferDist = $input->getOption('prefer-dist');
|
|
||||||
}
|
|
||||||
|
|
||||||
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
|
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
|
||||||
$authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
|
$authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
|
||||||
|
|
|
@ -123,27 +123,8 @@ EOT
|
||||||
|
|
||||||
$install = Installer::create($io, $composer);
|
$install = Installer::create($io, $composer);
|
||||||
|
|
||||||
$preferSource = false;
|
|
||||||
$preferDist = false;
|
|
||||||
|
|
||||||
$config = $composer->getConfig();
|
$config = $composer->getConfig();
|
||||||
|
list($preferSource, $preferDist) = $this->getPreferredInstallOptions($config, $input);
|
||||||
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')) {
|
|
||||||
$preferSource = $input->getOption('prefer-source');
|
|
||||||
$preferDist = $input->getOption('prefer-dist');
|
|
||||||
}
|
|
||||||
|
|
||||||
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
|
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
|
||||||
$authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
|
$authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
|
||||||
|
|
Loading…
Reference in New Issue