Adjust RepositoryManager to handle multiple repositories of one type
parent
33e7001d7e
commit
450095e61d
|
@ -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);
|
||||
|
|
|
@ -15,12 +15,14 @@ namespace Composer\Repository;
|
|||
/**
|
||||
* Repositories manager.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue