Sfoglia il codice sorgente

Merge pull request #1658 from miklosm/iss553

Adds 'prefer-source' option to config
Jordi Boggiano 12 anni fa
parent
commit
b10bd5f161

+ 3 - 0
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.

+ 4 - 0
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."

+ 11 - 4
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; }),

+ 21 - 2
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'))

+ 21 - 2
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'))

+ 1 - 0
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',