2011-09-25 18:00:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Repository;
|
|
|
|
|
2012-01-16 13:14:15 +00:00
|
|
|
use Composer\IO\IOInterface;
|
2012-04-09 14:36:06 +00:00
|
|
|
use Composer\Config;
|
2012-01-10 17:50:16 +00:00
|
|
|
|
2011-09-25 18:00:05 +00:00
|
|
|
/**
|
|
|
|
* Repositories manager.
|
|
|
|
*
|
2011-10-22 18:49:19 +00:00
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
2011-09-25 18:00:05 +00:00
|
|
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
2012-01-10 17:50:16 +00:00
|
|
|
* @author François Pluchino <francois.pluchino@opendisplay.com>
|
2011-09-25 18:00:05 +00:00
|
|
|
*/
|
|
|
|
class RepositoryManager
|
|
|
|
{
|
|
|
|
private $localRepository;
|
2012-04-14 13:45:25 +00:00
|
|
|
private $localDevRepository;
|
2011-09-25 18:00:05 +00:00
|
|
|
private $repositories = array();
|
2011-10-22 18:49:19 +00:00
|
|
|
private $repositoryClasses = array();
|
2012-01-16 13:14:15 +00:00
|
|
|
private $io;
|
2012-04-09 14:36:06 +00:00
|
|
|
private $config;
|
2012-01-10 17:50:16 +00:00
|
|
|
|
2012-04-09 14:36:06 +00:00
|
|
|
public function __construct(IOInterface $io, Config $config)
|
2012-01-10 17:50:16 +00:00
|
|
|
{
|
2012-01-16 13:14:15 +00:00
|
|
|
$this->io = $io;
|
2012-04-09 14:36:06 +00:00
|
|
|
$this->config = $config;
|
2012-01-10 17:50:16 +00:00
|
|
|
}
|
2011-09-25 18:00:05 +00:00
|
|
|
|
2011-10-01 12:33:25 +00:00
|
|
|
/**
|
|
|
|
* Searches for a package by it's name and version in managed repositories.
|
|
|
|
*
|
|
|
|
* @param string $name package name
|
|
|
|
* @param string $version package version
|
|
|
|
*
|
|
|
|
* @return PackageInterface|null
|
|
|
|
*/
|
|
|
|
public function findPackage($name, $version)
|
|
|
|
{
|
|
|
|
foreach ($this->repositories as $repository) {
|
|
|
|
if ($package = $repository->findPackage($name, $version)) {
|
|
|
|
return $package;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:02:08 +00:00
|
|
|
/**
|
|
|
|
* Searches for all packages matching a name and optionally a version in managed repositories.
|
|
|
|
*
|
|
|
|
* @param string $name package name
|
|
|
|
* @param string $version package version
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function findPackages($name, $version)
|
|
|
|
{
|
|
|
|
$packages = array();
|
|
|
|
|
|
|
|
foreach ($this->repositories as $repository) {
|
|
|
|
$packages = array_merge($packages, $repository->findPackages($name, $version));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $packages;
|
|
|
|
}
|
|
|
|
|
2011-09-25 18:00:05 +00:00
|
|
|
/**
|
2011-10-22 18:49:19 +00:00
|
|
|
* Adds repository
|
2011-09-25 18:00:05 +00:00
|
|
|
*
|
|
|
|
* @param RepositoryInterface $repository repository instance
|
|
|
|
*/
|
2011-10-22 18:49:19 +00:00
|
|
|
public function addRepository(RepositoryInterface $repository)
|
2011-09-25 18:00:05 +00:00
|
|
|
{
|
2011-10-22 18:49:19 +00:00
|
|
|
$this->repositories[] = $repository;
|
2011-09-25 18:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-22 20:20:30 +00:00
|
|
|
* Returns a new repository for a specific installation type.
|
2011-09-25 18:00:05 +00:00
|
|
|
*
|
2011-10-22 20:20:30 +00:00
|
|
|
* @param string $type repository type
|
|
|
|
* @param string $config repository configuration
|
2011-09-25 18:00:05 +00:00
|
|
|
* @return RepositoryInterface
|
|
|
|
* @throws InvalidArgumentException if repository for provided type is not registeterd
|
|
|
|
*/
|
2011-10-22 20:20:30 +00:00
|
|
|
public function createRepository($type, $config)
|
2011-09-25 18:00:05 +00:00
|
|
|
{
|
2011-10-22 18:49:19 +00:00
|
|
|
if (!isset($this->repositoryClasses[$type])) {
|
|
|
|
throw new \InvalidArgumentException('Repository type is not registered: '.$type);
|
2011-09-25 18:00:05 +00:00
|
|
|
}
|
|
|
|
|
2011-10-22 20:20:30 +00:00
|
|
|
$class = $this->repositoryClasses[$type];
|
2012-04-09 14:36:06 +00:00
|
|
|
return new $class($config, $this->io, $this->config);
|
2011-10-22 18:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2011-09-25 18:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all repositories, except local one.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getRepositories()
|
|
|
|
{
|
|
|
|
return $this->repositories;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets local repository for the project.
|
|
|
|
*
|
|
|
|
* @param RepositoryInterface $repository repository instance
|
|
|
|
*/
|
|
|
|
public function setLocalRepository(RepositoryInterface $repository)
|
|
|
|
{
|
|
|
|
$this->localRepository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns local repository for the project.
|
|
|
|
*
|
|
|
|
* @return RepositoryInterface
|
|
|
|
*/
|
|
|
|
public function getLocalRepository()
|
|
|
|
{
|
|
|
|
return $this->localRepository;
|
|
|
|
}
|
2012-04-14 13:45:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets localDev repository for the project.
|
|
|
|
*
|
|
|
|
* @param RepositoryInterface $repository repository instance
|
|
|
|
*/
|
|
|
|
public function setLocalDevRepository(RepositoryInterface $repository)
|
|
|
|
{
|
|
|
|
$this->localDevRepository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns localDev repository for the project.
|
|
|
|
*
|
|
|
|
* @return RepositoryInterface
|
|
|
|
*/
|
|
|
|
public function getLocalDevRepository()
|
|
|
|
{
|
|
|
|
return $this->localDevRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all local repositories for the project.
|
|
|
|
*
|
|
|
|
* @return array[RepositoryInterface]
|
|
|
|
*/
|
|
|
|
public function getLocalRepositories()
|
|
|
|
{
|
|
|
|
return array($this->localRepository, $this->localDevRepository);
|
|
|
|
}
|
2011-09-25 18:00:05 +00:00
|
|
|
}
|