From 44e76e06fcbe905bf22784b54848584c1a37de0c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 19 Feb 2012 19:00:12 +0100 Subject: [PATCH 1/2] Refactor repositories configuration --- src/Composer/Factory.php | 9 ++++++++- src/Composer/Package/Loader/RootPackageLoader.php | 11 +++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index e4c81e824..2bbbded74 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -51,6 +51,7 @@ class Factory // Configuration defaults $composerConfig = array( 'vendor-dir' => 'vendor', + 'repositories' => array(), ); $packageConfig = $file->read(); @@ -71,7 +72,13 @@ class Factory $rm = $this->createRepositoryManager($io); // load default repository unless it's explicitly disabled - if (!isset($packageConfig['repositories']['packagist']) || $packageConfig['repositories']['packagist'] !== false) { + $loadPackagist = true; + foreach ($packageConfig['repositories'] as $repo) { + if (isset($repo['packagist']) && $repo['packagist'] === false) { + $loadPackagist = false; + } + } + if ($loadPackagist) { $this->addPackagistRepository($rm); } diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index 294dd3f42..bd0848a0e 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -44,14 +44,17 @@ class RootPackageLoader extends ArrayLoader $package = parent::load($config); if (isset($config['repositories'])) { - foreach ($config['repositories'] as $repoName => $repo) { - if (false === $repo && 'packagist' === $repoName) { + foreach ($config['repositories'] as $index => $repo) { + if (isset($repo['packagist']) && $repo['packagist'] === false) { continue; } if (!is_array($repo)) { - throw new \UnexpectedValueException('Repository '.$repoName.' in '.$package->getPrettyName().' '.$package->getVersion().' should be an array, '.gettype($repo).' given'); + throw new \UnexpectedValueException('Repository '.$index.' should be an array, '.gettype($repo).' given'); } - $repository = $this->manager->createRepository(key($repo), current($repo)); + if (!isset($repo['type'])) { + throw new \UnexpectedValueException('Repository '.$index.' must have a type defined'); + } + $repository = $this->manager->createRepository($repo['type'], $repo); $this->manager->addRepository($repository); } $package->setRepositories($config['repositories']); From d0d5329f6fae5d520b290cd3b3554f0705492329 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 19 Feb 2012 19:12:56 +0100 Subject: [PATCH 2/2] Fix package repositories --- src/Composer/Repository/PackageRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/PackageRepository.php b/src/Composer/Repository/PackageRepository.php index 01b1b24c2..fe2e83187 100644 --- a/src/Composer/Repository/PackageRepository.php +++ b/src/Composer/Repository/PackageRepository.php @@ -33,7 +33,7 @@ class PackageRepository extends ArrayRepository */ public function __construct(array $config) { - $this->config = $config; + $this->config = $config['package']; } /**