Remove contains() from RepositoryInterface
parent
f0e709ad09
commit
6dbec8718d
|
@ -12,6 +12,8 @@
|
|||
|
||||
namespace Composer\DependencyResolver;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
|
||||
/**
|
||||
* A repository implementation that simply stores packages in an array
|
||||
*
|
||||
|
@ -24,11 +26,12 @@ class ArrayRepository implements RepositoryInterface
|
|||
/**
|
||||
* Adds a new package to the repository
|
||||
*
|
||||
* @param Package $package
|
||||
* @param PackageInterface $package
|
||||
*/
|
||||
public function addPackage(Package $package)
|
||||
public function addPackage(PackageInterface $package)
|
||||
{
|
||||
$this->packages[$package->getId()] = $package;
|
||||
$package->setRepository($this);
|
||||
$this->packages[] = $package;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,16 +44,6 @@ class ArrayRepository implements RepositoryInterface
|
|||
return $this->packages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a package is contained in this repository
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function contains(Package $package)
|
||||
{
|
||||
return isset($this->packages[$package->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of packages in this repository
|
||||
*
|
||||
|
|
|
@ -18,5 +18,4 @@ namespace Composer\DependencyResolver;
|
|||
interface RepositoryInterface extends \Countable
|
||||
{
|
||||
function getPackages();
|
||||
function contains(Package $package);
|
||||
}
|
||||
|
|
|
@ -255,7 +255,7 @@ class Solver
|
|||
$this->addedMap[$package->getId()] = true;
|
||||
|
||||
$dontFix = 0;
|
||||
if ($this->installed->contains($package) && !isset($this->fixMap[$package->getId()])) {
|
||||
if ($this->installed === $package->getRepository() && !isset($this->fixMap[$package->getId()])) {
|
||||
$dontFix = 1;
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ class Solver
|
|||
if ($dontFix) {
|
||||
$foundInstalled = false;
|
||||
foreach ($possibleRequires as $require) {
|
||||
if ($this->installed->contains($require)) {
|
||||
if ($this->installed === $require->getRepository()) {
|
||||
$foundInstalled = true;
|
||||
break;
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ class Solver
|
|||
$possibleConflicts = $this->pool->whatProvides($relation->getToPackageName(), $relation->getConstraint());
|
||||
|
||||
foreach ($possibleConflicts as $conflict) {
|
||||
if ($dontfix && $this->installed->contains($conflict)) {
|
||||
if ($dontfix && $this->installed === $conflict->getRepository()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -457,12 +457,12 @@ class Solver
|
|||
foreach ($job['packages'] as $package) {
|
||||
switch ($job['cmd']) {
|
||||
case 'fix':
|
||||
if ($this->installed->contains($package)) {
|
||||
if ($this->installed === $package->getRepository()) {
|
||||
$this->fixMap[$package->getId()] = true;
|
||||
}
|
||||
break;
|
||||
case 'update':
|
||||
if ($this->installed->contains($package)) {
|
||||
if ($this->installed === $package->getRepository()) {
|
||||
$this->updateMap[$package->getId()] = true;
|
||||
}
|
||||
break;
|
||||
|
@ -547,7 +547,7 @@ class Solver
|
|||
break;
|
||||
case 'lock':
|
||||
foreach ($job['packages'] as $package) {
|
||||
if ($this->installed->contains($package)) {
|
||||
if ($this->installed === $package->getRepository()) {
|
||||
$rule = $this->createInstallRule($package, self::RULE_JOB_LOCK);
|
||||
} else {
|
||||
$rule = $this->createRemoveRule($package, self::RULE_JOB_LOCK);
|
||||
|
@ -762,7 +762,7 @@ class Solver
|
|||
$minimizationsteps = 0;
|
||||
$installedPos = 0;
|
||||
|
||||
$this->installedPackages = array_values($this->installed->getPackages());
|
||||
$this->installedPackages = $this->installed->getPackages();
|
||||
|
||||
while (true) {
|
||||
|
||||
|
@ -798,7 +798,7 @@ class Solver
|
|||
if (count($this->installed) != count($this->updateMap)) {
|
||||
$prunedQueue = array();
|
||||
foreach ($decisionQueue as $literal) {
|
||||
if ($this->installed->contains($literal->getPackage())) {
|
||||
if ($this->installed === $literal->getPackage()->getRepository()) {
|
||||
$prunedQueue[] = $literal;
|
||||
if (isset($this->updateMap[$literal->getPackageId()])) {
|
||||
$prunedQueue = $decisionQueue;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
namespace Composer\Package;
|
||||
|
||||
use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface;
|
||||
use Composer\DependencyResolver\RepositoryInterface;
|
||||
|
||||
/**
|
||||
* Base class for packages providing name storage and default match implementation
|
||||
|
@ -22,6 +23,7 @@ use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface;
|
|||
abstract class BasePackage implements PackageInterface
|
||||
{
|
||||
protected $name;
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* All descendents' constructors should call this parent constructor
|
||||
|
@ -97,6 +99,19 @@ abstract class BasePackage implements PackageInterface
|
|||
return false;
|
||||
}
|
||||
|
||||
public function getRepository()
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
public function setRepository(RepositoryInterface $repository)
|
||||
{
|
||||
if ($this->repository) {
|
||||
throw new \LogicException('A package can only be added to one repository');
|
||||
}
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the package into a readable and unique string
|
||||
*
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
namespace Composer\Package;
|
||||
|
||||
use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface;
|
||||
use Composer\DependencyResolver\RepositoryInterface;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
|
@ -136,6 +137,20 @@ interface PackageInterface
|
|||
*/
|
||||
function getSuggests();
|
||||
|
||||
/**
|
||||
* Stores a reference to the repository that owns the package
|
||||
*
|
||||
* @param RepositoryInterface $repository
|
||||
*/
|
||||
function setRepository(RepositoryInterface $repository);
|
||||
|
||||
/**
|
||||
* Returns a reference to the repository that owns the package
|
||||
*
|
||||
* @return RepositoryInterface
|
||||
*/
|
||||
function getRepository();
|
||||
|
||||
/**
|
||||
* Converts the package into a readable and unique string
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue