浏览代码

Scratch 'prefer-source'; 'preferred-install' is the bee's knees

Miklós Márton 12 年之前
父节点
当前提交
72a4146383

+ 3 - 2
doc/04-schema.md

@@ -581,8 +581,9 @@ The following options are supported:
   higher if you have a slow connection or huge vendors.
   higher if you have a slow connection or huge vendors.
 * **use-include-path:** Defaults to `false`. If true, the Composer autoloader
 * **use-include-path:** Defaults to `false`. If true, the Composer autoloader
   will also look for classes in the PHP include path.
   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
 * **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
   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.
   behind a proxy or have somehow bad performances with the git protocol.

+ 3 - 3
res/composer-schema.json

@@ -116,9 +116,9 @@
                     "type": "boolean",
                     "type": "boolean",
                     "description": "If true, the Composer autoloader will also look for classes in the PHP include path."
                     "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": {
                 "notify-on-install": {
                     "type": "boolean",
                     "type": "boolean",

+ 3 - 3
src/Composer/Command/ConfigCommand.php

@@ -258,9 +258,9 @@ EOT
                 $booleanValidator,
                 $booleanValidator,
                 $booleanNormalizer
                 $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(
             'notify-on-install' => array(
                 $booleanValidator,
                 $booleanValidator,

+ 21 - 2
src/Composer/Command/InstallCommand.php

@@ -61,11 +61,30 @@ EOT
         $io = $this->getIO();
         $io = $this->getIO();
         $install = Installer::create($io, $composer);
         $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
         $install
             ->setDryRun($input->getOption('dry-run'))
             ->setDryRun($input->getOption('dry-run'))
             ->setVerbose($input->getOption('verbose'))
             ->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'))
             ->setDevMode($input->getOption('dev'))
             ->setRunScripts(!$input->getOption('no-scripts'))
             ->setRunScripts(!$input->getOption('no-scripts'))
             ->setOptimizeAutoloader($input->getOption('optimize-autoloader'))
             ->setOptimizeAutoloader($input->getOption('optimize-autoloader'))

+ 21 - 2
src/Composer/Command/UpdateCommand.php

@@ -64,11 +64,30 @@ EOT
         $io = $this->getIO();
         $io = $this->getIO();
         $install = Installer::create($io, $composer);
         $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
         $install
             ->setDryRun($input->getOption('dry-run'))
             ->setDryRun($input->getOption('dry-run'))
             ->setVerbose($input->getOption('verbose'))
             ->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'))
             ->setDevMode(!$input->getOption('no-dev'))
             ->setRunScripts(!$input->getOption('no-scripts'))
             ->setRunScripts(!$input->getOption('no-scripts'))
             ->setOptimizeAutoloader($input->getOption('optimize-autoloader'))
             ->setOptimizeAutoloader($input->getOption('optimize-autoloader'))

+ 1 - 1
src/Composer/Config.php

@@ -22,7 +22,7 @@ class Config
     public static $defaultConfig = array(
     public static $defaultConfig = array(
         'process-timeout' => 300,
         'process-timeout' => 300,
         'use-include-path' => false,
         'use-include-path' => false,
-        'prefer-source' => false,
+        'preferred-install' => 'auto',
         'notify-on-install' => true,
         'notify-on-install' => true,
         'github-protocols' => array('git', 'https', 'http'),
         'github-protocols' => array('git', 'https', 'http'),
         'vendor-dir' => 'vendor',
         'vendor-dir' => 'vendor',