diff --git a/doc/04-schema.md b/doc/04-schema.md index 74c7510de..a222c06e0 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -581,6 +581,9 @@ The following options are supported: higher if you have a slow connection or huge vendors. * **use-include-path:** Defaults to `false`. If true, the Composer autoloader will also look for classes in the PHP include path. +* **preferred-install:** Defaults to `auto` and can be any of `source`, `dist` or + `auto`. This option allows you to set the install method Composer will prefer to + use. * **github-protocols:** Defaults to `["git", "https", "http"]`. A list of protocols to use for github.com clones, in priority order. Use this if you are behind a proxy or have somehow bad performances with the git protocol. diff --git a/res/composer-schema.json b/res/composer-schema.json index e8c0474e7..aefaa0463 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -116,6 +116,10 @@ "type": "boolean", "description": "If true, the Composer autoloader will also look for classes in the PHP include path." }, + "preferred-install": { + "type": "string", + "description": "The install method Composer will prefer to use, defaults to auto and can be any of source, dist or auto." + }, "notify-on-install": { "type": "boolean", "description": "Composer allows repositories to define a notification URL, so that they get notified whenever a package from that repository is installed. This option allows you to disable that behaviour, defaults to true." diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 4c2e9e5d8..f447a70ba 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -248,16 +248,23 @@ EOT return $this->configSource->addConfigSetting('github-oauth.'.$matches[1], $values[0]); } + $booleanValidator = function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }; + $booleanNormalizer = function ($val) { return $val !== 'false' && (bool) $val; }; + // handle config values $uniqueConfigValues = array( 'process-timeout' => array('is_numeric', 'intval'), 'use-include-path' => array( - function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }, - function ($val) { return $val !== 'false' && (bool) $val; } + $booleanValidator, + $booleanNormalizer + ), + 'preferred-install' => array( + function ($val) { return in_array($val, array('auto', 'source', 'dist'), true); }, + function ($val) { return $val; } ), 'notify-on-install' => array( - function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }, - function ($val) { return $val !== 'false' && (bool) $val; } + $booleanValidator, + $booleanNormalizer ), 'vendor-dir' => array('is_string', function ($val) { return $val; }), 'bin-dir' => array('is_string', function ($val) { return $val; }), diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index c578a308c..5be76257b 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -61,11 +61,30 @@ EOT $io = $this->getIO(); $install = Installer::create($io, $composer); + $preferSource = false; + $preferDist = false; + switch ($composer->getConfig()->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'); + } + $install ->setDryRun($input->getOption('dry-run')) ->setVerbose($input->getOption('verbose')) - ->setPreferSource($input->getOption('prefer-source')) - ->setPreferDist($input->getOption('prefer-dist')) + ->setPreferSource($preferSource) + ->setPreferDist($preferDist) ->setDevMode($input->getOption('dev')) ->setRunScripts(!$input->getOption('no-scripts')) ->setOptimizeAutoloader($input->getOption('optimize-autoloader')) diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index f1ac08f28..7c75fb4db 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -64,11 +64,30 @@ EOT $io = $this->getIO(); $install = Installer::create($io, $composer); + $preferSource = false; + $preferDist = false; + switch ($composer->getConfig()->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'); + } + $install ->setDryRun($input->getOption('dry-run')) ->setVerbose($input->getOption('verbose')) - ->setPreferSource($input->getOption('prefer-source')) - ->setPreferDist($input->getOption('prefer-dist')) + ->setPreferSource($preferSource) + ->setPreferDist($preferDist) ->setDevMode(!$input->getOption('no-dev')) ->setRunScripts(!$input->getOption('no-scripts')) ->setOptimizeAutoloader($input->getOption('optimize-autoloader')) diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 0d9aa22b7..54d3961ac 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -22,6 +22,7 @@ class Config public static $defaultConfig = array( 'process-timeout' => 300, 'use-include-path' => false, + 'preferred-install' => 'auto', 'notify-on-install' => true, 'github-protocols' => array('git', 'https', 'http'), 'vendor-dir' => 'vendor',