From 450095e61d095dc316d100e46f7e1a35b21f2d63 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 22 Oct 2011 20:49:19 +0200 Subject: [PATCH] Adjust RepositoryManager to handle multiple repositories of one type --- bin/composer | 4 ++- src/Composer/Repository/RepositoryManager.php | 30 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/bin/composer b/bin/composer index 201363092..89bcdbfb5 100755 --- a/bin/composer +++ b/bin/composer @@ -14,7 +14,9 @@ use Composer\Console\Application as ComposerApplication; // initialize repository manager $rm = new Repository\RepositoryManager(); $rm->setLocalRepository(new Repository\FilesystemRepository(new JsonFile('.composer/installed.json'))); -$rm->setRepository('Packagist', new Repository\ComposerRepository('http://packagist.org')); +$rm->addRepository(new Repository\ComposerRepository('http://packagist.org')); +$rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository'); +$rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository'); // initialize download manager $dm = new Downloader\DownloadManager($preferSource = false); diff --git a/src/Composer/Repository/RepositoryManager.php b/src/Composer/Repository/RepositoryManager.php index 4535d4945..dc7766cfa 100644 --- a/src/Composer/Repository/RepositoryManager.php +++ b/src/Composer/Repository/RepositoryManager.php @@ -15,12 +15,14 @@ namespace Composer\Repository; /** * Repositories manager. * + * @author Jordi Boggiano * @author Konstantin Kudryashov */ class RepositoryManager { private $localRepository; private $repositories = array(); + private $repositoryClasses = array(); /** * Searches for a package by it's name and version in managed repositories. @@ -40,18 +42,17 @@ class RepositoryManager } /** - * Sets repository with specific name. + * Adds repository * - * @param string $type repository name * @param RepositoryInterface $repository repository instance */ - public function setRepository($type, RepositoryInterface $repository) + public function addRepository(RepositoryInterface $repository) { - $this->repositories[$type] = $repository; + $this->repositories[] = $repository; } /** - * Returns repository for a specific installation type. + * Returns repository class for a specific installation type. * * @param string $type installation type * @@ -59,13 +60,24 @@ class RepositoryManager * * @throws InvalidArgumentException if repository for provided type is not registeterd */ - public function getRepository($type) + public function getRepositoryClass($type) { - if (!isset($this->repositories[$type])) { - throw new \InvalidArgumentException('Repository is not registered: '.$type); + if (!isset($this->repositoryClasses[$type])) { + throw new \InvalidArgumentException('Repository type is not registered: '.$type); } - return $this->repositories[$type]; + return $this->repositoryClasses[$type]; + } + + /** + * Stores repository class for a specific installation type. + * + * @param string $type installation type + * @param string $class class name of the repo implementation + */ + public function setRepositoryClass($type, $class) + { + $this->repositoryClasses[$type] = $class; } /**