1
0
Fork 0

Use policy rule instead of stacking up another repo to prioritize aliased packages

pull/350/head
Jordi Boggiano 2012-02-22 09:40:05 +01:00
parent 59d2b1145c
commit 956b54e516
2 changed files with 12 additions and 3 deletions

View File

@ -106,7 +106,6 @@ EOT
} }
// prepare aliased packages // prepare aliased packages
$aliasRepo = new ArrayRepository;
if (!$update && $composer->getLocker()->isLocked()) { if (!$update && $composer->getLocker()->isLocked()) {
$aliases = $composer->getLocker()->getAliases(); $aliases = $composer->getLocker()->getAliases();
} else { } else {
@ -114,14 +113,13 @@ EOT
} }
foreach ($aliases as $alias) { foreach ($aliases as $alias) {
foreach ($repoManager->findPackages($alias['package'], $alias['version']) as $package) { foreach ($repoManager->findPackages($alias['package'], $alias['version']) as $package) {
$aliasRepo->addPackage(new AliasPackage($package, $alias['alias'])); $package->getRepository()->addPackage(new AliasPackage($package, $alias['alias']));
} }
foreach ($repoManager->getLocalRepository()->findPackages($alias['package'], $alias['version']) as $package) { foreach ($repoManager->getLocalRepository()->findPackages($alias['package'], $alias['version']) as $package) {
$repoManager->getLocalRepository()->addPackage(new AliasPackage($package, $alias['alias'])); $repoManager->getLocalRepository()->addPackage(new AliasPackage($package, $alias['alias']));
$repoManager->getLocalRepository()->removePackage($package); $repoManager->getLocalRepository()->removePackage($package);
} }
} }
$repoManager->addRepository($aliasRepo);
// creating repository pool // creating repository pool
$pool = new Pool; $pool = new Pool;

View File

@ -14,6 +14,7 @@ namespace Composer\DependencyResolver;
use Composer\Repository\RepositoryInterface; use Composer\Repository\RepositoryInterface;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Package\AliasPackage;
use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Package\LinkConstraint\VersionConstraint;
/** /**
@ -103,6 +104,16 @@ class DefaultPolicy implements PolicyInterface
public function compareByPriorityPreferInstalled(Pool $pool, array $installedMap, PackageInterface $a, PackageInterface $b, $ignoreReplace = false) public function compareByPriorityPreferInstalled(Pool $pool, array $installedMap, PackageInterface $a, PackageInterface $b, $ignoreReplace = false)
{ {
if ($a->getRepository() === $b->getRepository()) { if ($a->getRepository() === $b->getRepository()) {
if ($a->getName() === $b->getName()) {
$aAliased = $a instanceof AliasPackage;
$bAliased = $b instanceof AliasPackage;
if ($aAliased && !$bAliased) {
return -1; // use a
}
if (!$aAliased && $bAliased) {
return 1; // use b
}
}
if (!$ignoreReplace) { if (!$ignoreReplace) {
// return original, not replaced // return original, not replaced