From 859c8f5bb3b8998e351c1dd52aab8d46e81cb222 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 4 Dec 2014 15:10:56 +0100 Subject: [PATCH] Use the repositories configured in composer.json for the require command --- src/Composer/Command/InitCommand.php | 3 ++- src/Composer/Command/RequireCommand.php | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 462b6d438..38dc2c4a5 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -33,8 +33,9 @@ use Symfony\Component\Process\ExecutableFinder; */ class InitCommand extends Command { + protected $repos; + private $gitConfig; - private $repos; private $pool; public function parseAuthorString($author) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index d0a63f1f3..f20c0420c 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -23,6 +23,8 @@ use Composer\Json\JsonManipulator; use Composer\Package\Version\VersionParser; use Composer\Plugin\CommandEvent; use Composer\Plugin\PluginEvents; +use Composer\Repository\CompositeRepository; +use Composer\Repository\PlatformRepository; /** * @author Jérémy Romey @@ -78,14 +80,22 @@ EOT } $json = new JsonFile($file); - $composer = $json->read(); + $composerDefinition = $json->read(); $composerBackup = file_get_contents($json->getPath()); + $composer = $this->getComposer(); + $repos = $composer->getRepositoryManager()->getRepositories(); + + $this->repos = new CompositeRepository(array_merge( + array(new PlatformRepository), + $repos + )); + $requirements = $this->determineRequirements($input, $output, $input->getArgument('packages')); $requireKey = $input->getOption('dev') ? 'require-dev' : 'require'; $removeKey = $input->getOption('dev') ? 'require' : 'require-dev'; - $baseRequirements = array_key_exists($requireKey, $composer) ? $composer[$requireKey] : array(); + $baseRequirements = array_key_exists($requireKey, $composerDefinition) ? $composerDefinition[$requireKey] : array(); $requirements = $this->formatRequirements($requirements); // validate requirements format @@ -98,13 +108,13 @@ EOT foreach ($requirements as $package => $version) { $baseRequirements[$package] = $version; - if (isset($composer[$removeKey][$package])) { - unset($composer[$removeKey][$package]); + if (isset($composerDefinition[$removeKey][$package])) { + unset($composerDefinition[$removeKey][$package]); } } - $composer[$requireKey] = $baseRequirements; - $json->write($composer); + $composerDefinition[$requireKey] = $baseRequirements; + $json->write($composerDefinition); } $output->writeln(''.$file.' has been '.($newlyCreated ? 'created' : 'updated').''); @@ -115,7 +125,6 @@ EOT $updateDevMode = !$input->getOption('update-no-dev'); // Update packages - $composer = $this->getComposer(); $composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress')); $io = $this->getIO();