From c92c69b10e394d57e5430737b91b801ff8ec41f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Mon, 4 Mar 2013 20:23:55 +0100 Subject: [PATCH 1/5] Config option 'prefer-source' added to schema, refs #553 --- doc/04-schema.md | 2 ++ res/composer-schema.json | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/doc/04-schema.md b/doc/04-schema.md index 74c7510de..f08290ace 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -581,6 +581,8 @@ 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. * **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..d6a658e5d 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." }, + "prefer-source": { + "type": "boolean", + "description": "If true, Composer will always prefer source installs." + }, "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." From 0f8530ef56643d6b6d4aa13565671fff92e9ad6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Mon, 4 Mar 2013 20:27:59 +0100 Subject: [PATCH 2/5] Support for 'prefer-source' config setting, refs #553 --- src/Composer/Command/ConfigCommand.php | 4 ++++ src/Composer/Config.php | 1 + 2 files changed, 5 insertions(+) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 4c2e9e5d8..03f090231 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -255,6 +255,10 @@ EOT function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }, function ($val) { return $val !== 'false' && (bool) $val; } ), + 'prefer-source' => array( + function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }, + function ($val) { return $val !== 'false' && (bool) $val; } + ), 'notify-on-install' => array( function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }, function ($val) { return $val !== 'false' && (bool) $val; } diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 0d9aa22b7..ce79508ed 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, + 'prefer-source' => false, 'notify-on-install' => true, 'github-protocols' => array('git', 'https', 'http'), 'vendor-dir' => 'vendor', From 0d81ab7f46bc9d9b4d2501224eec9abb49a30f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Mon, 4 Mar 2013 20:29:14 +0100 Subject: [PATCH 3/5] Install/update now uses the new config variable 'prefer-source', fixes #553 --- src/Composer/Command/InstallCommand.php | 2 +- src/Composer/Command/UpdateCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index c578a308c..7bcda88ab 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -64,7 +64,7 @@ EOT $install ->setDryRun($input->getOption('dry-run')) ->setVerbose($input->getOption('verbose')) - ->setPreferSource($input->getOption('prefer-source')) + ->setPreferSource($input->getOption('prefer-source') || $composer->getConfig()->get('prefer-source')) ->setPreferDist($input->getOption('prefer-dist')) ->setDevMode($input->getOption('dev')) ->setRunScripts(!$input->getOption('no-scripts')) diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index f1ac08f28..6515bbb83 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -67,7 +67,7 @@ EOT $install ->setDryRun($input->getOption('dry-run')) ->setVerbose($input->getOption('verbose')) - ->setPreferSource($input->getOption('prefer-source')) + ->setPreferSource($input->getOption('prefer-source') || $composer->getConfig()->get('prefer-source')) ->setPreferDist($input->getOption('prefer-dist')) ->setDevMode(!$input->getOption('no-dev')) ->setRunScripts(!$input->getOption('no-scripts')) From 9110c6413e8aba8890432315465d7644a2a70182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Mon, 4 Mar 2013 20:35:29 +0100 Subject: [PATCH 4/5] Minor code reorg to reduce duplication --- src/Composer/Command/ConfigCommand.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 03f090231..3025742bc 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -248,20 +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 ), 'prefer-source' => array( - function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }, - function ($val) { return $val !== 'false' && (bool) $val; } + $booleanValidator, + $booleanNormalizer ), '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; }), From 72a4146383dd60d182c24404cf59e9978a7cabf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Tue, 5 Mar 2013 12:56:09 +0100 Subject: [PATCH 5/5] Scratch 'prefer-source'; 'preferred-install' is the bee's knees --- doc/04-schema.md | 5 +++-- res/composer-schema.json | 6 +++--- src/Composer/Command/ConfigCommand.php | 6 +++--- src/Composer/Command/InstallCommand.php | 23 +++++++++++++++++++++-- src/Composer/Command/UpdateCommand.php | 23 +++++++++++++++++++++-- src/Composer/Config.php | 2 +- 6 files changed, 52 insertions(+), 13 deletions(-) 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',