1
0
Fork 0

Adjust RepositoryManager to handle multiple repositories of one type

pull/61/head
Jordi Boggiano 2011-10-22 20:49:19 +02:00
parent 33e7001d7e
commit 450095e61d
2 changed files with 24 additions and 10 deletions

View File

@ -14,7 +14,9 @@ use Composer\Console\Application as ComposerApplication;
// initialize repository manager // initialize repository manager
$rm = new Repository\RepositoryManager(); $rm = new Repository\RepositoryManager();
$rm->setLocalRepository(new Repository\FilesystemRepository(new JsonFile('.composer/installed.json'))); $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 // initialize download manager
$dm = new Downloader\DownloadManager($preferSource = false); $dm = new Downloader\DownloadManager($preferSource = false);

View File

@ -15,12 +15,14 @@ namespace Composer\Repository;
/** /**
* Repositories manager. * Repositories manager.
* *
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Konstantin Kudryashov <ever.zet@gmail.com> * @author Konstantin Kudryashov <ever.zet@gmail.com>
*/ */
class RepositoryManager class RepositoryManager
{ {
private $localRepository; private $localRepository;
private $repositories = array(); private $repositories = array();
private $repositoryClasses = array();
/** /**
* Searches for a package by it's name and version in managed repositories. * 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 * @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 * @param string $type installation type
* *
@ -59,13 +60,24 @@ class RepositoryManager
* *
* @throws InvalidArgumentException if repository for provided type is not registeterd * @throws InvalidArgumentException if repository for provided type is not registeterd
*/ */
public function getRepository($type) public function getRepositoryClass($type)
{ {
if (!isset($this->repositories[$type])) { if (!isset($this->repositoryClasses[$type])) {
throw new \InvalidArgumentException('Repository is not registered: '.$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;
} }
/** /**