diff --git a/doc/04-schema.md b/doc/04-schema.md index f08290ace..a222c06e0 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -581,8 +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. -* **prefer-source:** Defaults to `false`. If true, Composer will always prefer - source installs. +* **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 d6a658e5d..aefaa0463 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -116,9 +116,9 @@ "type": "boolean", "description": "If true, the Composer autoloader will also look for classes in the PHP include path." }, - "prefer-source": { - "type": "boolean", - "description": "If true, Composer will always prefer source installs." + "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", diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 3025742bc..f447a70ba 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -258,9 +258,9 @@ EOT $booleanValidator, $booleanNormalizer ), - 'prefer-source' => array( - $booleanValidator, - $booleanNormalizer + 'preferred-install' => array( + function ($val) { return in_array($val, array('auto', 'source', 'dist'), true); }, + function ($val) { return $val; } ), 'notify-on-install' => array( $booleanValidator, diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 7bcda88ab..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') || $composer->getConfig()->get('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 6515bbb83..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') || $composer->getConfig()->get('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 ce79508ed..54d3961ac 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -22,7 +22,7 @@ class Config public static $defaultConfig = array( 'process-timeout' => 300, 'use-include-path' => false, - 'prefer-source' => false, + 'preferred-install' => 'auto', 'notify-on-install' => true, 'github-protocols' => array('git', 'https', 'http'), 'vendor-dir' => 'vendor',