1
0
Fork 0

Remove contains() from RepositoryInterface

pull/1/head
Jordi Boggiano 2011-04-17 22:59:23 +02:00
parent f0e709ad09
commit 6dbec8718d
5 changed files with 44 additions and 22 deletions

View File

@ -12,6 +12,8 @@
namespace Composer\DependencyResolver; namespace Composer\DependencyResolver;
use Composer\Package\PackageInterface;
/** /**
* A repository implementation that simply stores packages in an array * 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 * 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; 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 * Returns the number of packages in this repository
* *

View File

@ -18,5 +18,4 @@ namespace Composer\DependencyResolver;
interface RepositoryInterface extends \Countable interface RepositoryInterface extends \Countable
{ {
function getPackages(); function getPackages();
function contains(Package $package);
} }

View File

@ -255,7 +255,7 @@ class Solver
$this->addedMap[$package->getId()] = true; $this->addedMap[$package->getId()] = true;
$dontFix = 0; $dontFix = 0;
if ($this->installed->contains($package) && !isset($this->fixMap[$package->getId()])) { if ($this->installed === $package->getRepository() && !isset($this->fixMap[$package->getId()])) {
$dontFix = 1; $dontFix = 1;
} }
@ -274,7 +274,7 @@ class Solver
if ($dontFix) { if ($dontFix) {
$foundInstalled = false; $foundInstalled = false;
foreach ($possibleRequires as $require) { foreach ($possibleRequires as $require) {
if ($this->installed->contains($require)) { if ($this->installed === $require->getRepository()) {
$foundInstalled = true; $foundInstalled = true;
break; break;
} }
@ -297,7 +297,7 @@ class Solver
$possibleConflicts = $this->pool->whatProvides($relation->getToPackageName(), $relation->getConstraint()); $possibleConflicts = $this->pool->whatProvides($relation->getToPackageName(), $relation->getConstraint());
foreach ($possibleConflicts as $conflict) { foreach ($possibleConflicts as $conflict) {
if ($dontfix && $this->installed->contains($conflict)) { if ($dontfix && $this->installed === $conflict->getRepository()) {
continue; continue;
} }
@ -457,12 +457,12 @@ class Solver
foreach ($job['packages'] as $package) { foreach ($job['packages'] as $package) {
switch ($job['cmd']) { switch ($job['cmd']) {
case 'fix': case 'fix':
if ($this->installed->contains($package)) { if ($this->installed === $package->getRepository()) {
$this->fixMap[$package->getId()] = true; $this->fixMap[$package->getId()] = true;
} }
break; break;
case 'update': case 'update':
if ($this->installed->contains($package)) { if ($this->installed === $package->getRepository()) {
$this->updateMap[$package->getId()] = true; $this->updateMap[$package->getId()] = true;
} }
break; break;
@ -547,7 +547,7 @@ class Solver
break; break;
case 'lock': case 'lock':
foreach ($job['packages'] as $package) { foreach ($job['packages'] as $package) {
if ($this->installed->contains($package)) { if ($this->installed === $package->getRepository()) {
$rule = $this->createInstallRule($package, self::RULE_JOB_LOCK); $rule = $this->createInstallRule($package, self::RULE_JOB_LOCK);
} else { } else {
$rule = $this->createRemoveRule($package, self::RULE_JOB_LOCK); $rule = $this->createRemoveRule($package, self::RULE_JOB_LOCK);
@ -762,7 +762,7 @@ class Solver
$minimizationsteps = 0; $minimizationsteps = 0;
$installedPos = 0; $installedPos = 0;
$this->installedPackages = array_values($this->installed->getPackages()); $this->installedPackages = $this->installed->getPackages();
while (true) { while (true) {
@ -798,7 +798,7 @@ class Solver
if (count($this->installed) != count($this->updateMap)) { if (count($this->installed) != count($this->updateMap)) {
$prunedQueue = array(); $prunedQueue = array();
foreach ($decisionQueue as $literal) { foreach ($decisionQueue as $literal) {
if ($this->installed->contains($literal->getPackage())) { if ($this->installed === $literal->getPackage()->getRepository()) {
$prunedQueue[] = $literal; $prunedQueue[] = $literal;
if (isset($this->updateMap[$literal->getPackageId()])) { if (isset($this->updateMap[$literal->getPackageId()])) {
$prunedQueue = $decisionQueue; $prunedQueue = $decisionQueue;

View File

@ -13,6 +13,7 @@
namespace Composer\Package; namespace Composer\Package;
use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface; use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface;
use Composer\DependencyResolver\RepositoryInterface;
/** /**
* Base class for packages providing name storage and default match implementation * 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 abstract class BasePackage implements PackageInterface
{ {
protected $name; protected $name;
protected $repository;
/** /**
* All descendents' constructors should call this parent constructor * All descendents' constructors should call this parent constructor
@ -97,6 +99,19 @@ abstract class BasePackage implements PackageInterface
return false; 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 * Converts the package into a readable and unique string
* *

View File

@ -13,6 +13,7 @@
namespace Composer\Package; namespace Composer\Package;
use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface; use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface;
use Composer\DependencyResolver\RepositoryInterface;
/** /**
* @author Nils Adermann <naderman@naderman.de> * @author Nils Adermann <naderman@naderman.de>
@ -136,6 +137,20 @@ interface PackageInterface
*/ */
function getSuggests(); 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 * Converts the package into a readable and unique string
* *