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;
|
2013-11-19 16:45:28 +00:00
|
|
|
use Composer\EventDispatcher\EventDispatcher;
|
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;
|
|
|
|
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;
|
2013-11-19 16:45:28 +00:00
|
|
|
private $eventDispatcher;
|
2012-01-10 17:50:16 +00:00
|
|
|
|
2013-11-19 16:45:28 +00:00
|
|
|
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
|
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;
|
2013-11-19 16:45:28 +00:00
|
|
|
$this->eventDispatcher = $eventDispatcher;
|
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.
|
|
|
|
*
|
2012-05-22 10:07:08 +00:00
|
|
|
* @param string $name package name
|
|
|
|
* @param string $version package version
|
2011-10-01 12:33:25 +00:00
|
|
|
*
|
2012-05-22 10:07:08 +00:00
|
|
|
* @return PackageInterface|null
|
2011-10-01 12:33:25 +00:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
2012-05-22 10:07:08 +00:00
|
|
|
* @param string $name package name
|
|
|
|
* @param string $version package version
|
2012-02-21 13:02:08 +00:00
|
|
|
*
|
2012-05-22 10:07:08 +00:00
|
|
|
* @return array
|
2012-02-21 13:02:08 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
*
|
2012-05-22 10:07:08 +00:00
|
|
|
* @param RepositoryInterface $repository repository instance
|
2011-09-25 18:00:05 +00:00
|
|
|
*/
|
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
|
|
|
*
|
2013-06-13 11:28:24 +00:00
|
|
|
* @param string $type repository type
|
|
|
|
* @param string $config repository configuration
|
2012-05-22 10:07:08 +00:00
|
|
|
* @return RepositoryInterface
|
2013-06-13 00:05:44 +00:00
|
|
|
* @throws \InvalidArgumentException if repository for provided type is not registered
|
2011-09-25 18:00:05 +00:00
|
|
|
*/
|
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-05-22 10:07:08 +00:00
|
|
|
|
2013-11-19 16:45:28 +00:00
|
|
|
return new $class($config, $this->io, $this->config, $this->eventDispatcher);
|
2011-10-22 18:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores repository class for a specific installation type.
|
|
|
|
*
|
2012-05-22 10:07:08 +00:00
|
|
|
* @param string $type installation type
|
|
|
|
* @param string $class class name of the repo implementation
|
2011-10-22 18:49:19 +00:00
|
|
|
*/
|
|
|
|
public function setRepositoryClass($type, $class)
|
|
|
|
{
|
|
|
|
$this->repositoryClasses[$type] = $class;
|
2011-09-25 18:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all repositories, except local one.
|
|
|
|
*
|
2012-05-22 10:07:08 +00:00
|
|
|
* @return array
|
2011-09-25 18:00:05 +00:00
|
|
|
*/
|
|
|
|
public function getRepositories()
|
|
|
|
{
|
|
|
|
return $this->repositories;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets local repository for the project.
|
|
|
|
*
|
2013-04-28 20:32:46 +00:00
|
|
|
* @param WritableRepositoryInterface $repository repository instance
|
2011-09-25 18:00:05 +00:00
|
|
|
*/
|
2013-04-28 20:32:46 +00:00
|
|
|
public function setLocalRepository(WritableRepositoryInterface $repository)
|
2011-09-25 18:00:05 +00:00
|
|
|
{
|
|
|
|
$this->localRepository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns local repository for the project.
|
|
|
|
*
|
2013-04-28 20:32:46 +00:00
|
|
|
* @return WritableRepositoryInterface
|
2011-09-25 18:00:05 +00:00
|
|
|
*/
|
|
|
|
public function getLocalRepository()
|
|
|
|
{
|
|
|
|
return $this->localRepository;
|
|
|
|
}
|
2012-04-14 13:45:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all local repositories for the project.
|
|
|
|
*
|
2013-03-03 16:32:41 +00:00
|
|
|
* @deprecated getLocalDevRepository is gone, so this is useless now, just use getLocalRepository instead
|
2012-06-23 09:42:13 +00:00
|
|
|
* @return array[WritableRepositoryInterface]
|
2012-04-14 13:45:25 +00:00
|
|
|
*/
|
|
|
|
public function getLocalRepositories()
|
|
|
|
{
|
2013-03-02 23:41:12 +00:00
|
|
|
trigger_error('This method is deprecated, use getLocalRepository instead since the getLocalDevRepository is now gone', E_USER_DEPRECATED);
|
|
|
|
|
|
|
|
return array($this->localRepository);
|
2012-04-14 13:45:25 +00:00
|
|
|
}
|
2011-09-25 18:00:05 +00:00
|
|
|
}
|