private function aliasPlatformPackages(PlatformRepository $platformRepo, $aliases)
 {
     foreach ($aliases as $package => $versions) {
         foreach ($versions as $version => $alias) {
             $packages = $platformRepo->findPackages($package, $version);
             foreach ($packages as $package) {
                 $aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
                 $aliasPackage->setRootPackageAlias(true);
                 $platformRepo->addPackage($aliasPackage);
             }
         }
     }
 }
 public function testSelectLocalReposFirst()
 {
     $this->repoImportant = new ArrayRepository();
     $this->repo->addPackage($packageA = $this->getPackage('A', 'dev-master'));
     $this->repo->addPackage($packageAAlias = new AliasPackage($packageA, '2.1.9999999.9999999-dev', '2.1.x-dev'));
     $this->repoImportant->addPackage($packageAImportant = $this->getPackage('A', 'dev-feature-a'));
     $this->repoImportant->addPackage($packageAAliasImportant = new AliasPackage($packageAImportant, '2.1.9999999.9999999-dev', '2.1.x-dev'));
     $this->repoImportant->addPackage($packageA2Important = $this->getPackage('A', 'dev-master'));
     $this->repoImportant->addPackage($packageA2AliasImportant = new AliasPackage($packageA2Important, '2.1.9999999.9999999-dev', '2.1.x-dev'));
     $packageAAliasImportant->setRootPackageAlias(true);
     $this->pool->addRepository($this->repoInstalled);
     $this->pool->addRepository($this->repoImportant);
     $this->pool->addRepository($this->repo);
     $packages = $this->pool->whatProvides('a', new Constraint('=', '2.1.9999999.9999999-dev'));
     $literals = array();
     foreach ($packages as $package) {
         $literals[] = $package->getId();
     }
     $expected = array($packageAAliasImportant->getId());
     $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals);
     $this->assertEquals($expected, $selected);
 }
示例#3
0
 /**
  * Adds a repository and its packages to this package pool
  *
  * @param RepositoryInterface $repo        A package repository
  * @param array               $rootAliases
  */
 public function addRepository(RepositoryInterface $repo, $rootAliases = array())
 {
     if ($repo instanceof CompositeRepository) {
         $repos = $repo->getRepositories();
     } else {
         $repos = array($repo);
     }
     foreach ($repos as $repo) {
         $this->repositories[] = $repo;
         $exempt = $repo instanceof PlatformRepository || $repo instanceof InstalledRepositoryInterface;
         if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
             $this->providerRepos[] = $repo;
             $repo->setRootAliases($rootAliases);
             $repo->resetPackageIds();
         } elseif ($repo instanceof StreamableRepositoryInterface) {
             foreach ($repo->getMinimalPackages() as $package) {
                 $name = $package['name'];
                 $version = $package['version'];
                 $stability = VersionParser::parseStability($version);
                 // collect names
                 $names = array($name => true);
                 if (isset($package['provide'])) {
                     foreach ($package['provide'] as $target => $constraint) {
                         $names[$target] = true;
                     }
                 }
                 if (isset($package['replace'])) {
                     foreach ($package['replace'] as $target => $constraint) {
                         $names[$target] = true;
                     }
                 }
                 $names = array_keys($names);
                 if ($exempt || $this->isPackageAcceptable($names, $stability)) {
                     $package['id'] = $this->id++;
                     $this->packages[] = $package;
                     foreach ($names as $provided) {
                         $this->packageByName[$provided][$package['id']] = $this->packages[$this->id - 2];
                     }
                     // handle root package aliases
                     unset($rootAliasData);
                     if (isset($rootAliases[$name][$version])) {
                         $rootAliasData = $rootAliases[$name][$version];
                     } elseif (isset($package['alias_normalized']) && isset($rootAliases[$name][$package['alias_normalized']])) {
                         $rootAliasData = $rootAliases[$name][$package['alias_normalized']];
                     }
                     if (isset($rootAliasData)) {
                         $alias = $package;
                         unset($alias['raw']);
                         $alias['version'] = $rootAliasData['alias_normalized'];
                         $alias['alias'] = $rootAliasData['alias'];
                         $alias['alias_of'] = $package['id'];
                         $alias['id'] = $this->id++;
                         $alias['root_alias'] = true;
                         $this->packages[] = $alias;
                         foreach ($names as $provided) {
                             $this->packageByName[$provided][$alias['id']] = $this->packages[$this->id - 2];
                         }
                     }
                     // handle normal package aliases
                     if (isset($package['alias'])) {
                         $alias = $package;
                         unset($alias['raw']);
                         $alias['version'] = $package['alias_normalized'];
                         $alias['alias'] = $package['alias'];
                         $alias['alias_of'] = $package['id'];
                         $alias['id'] = $this->id++;
                         $this->packages[] = $alias;
                         foreach ($names as $provided) {
                             $this->packageByName[$provided][$alias['id']] = $this->packages[$this->id - 2];
                         }
                     }
                 }
             }
         } else {
             foreach ($repo->getPackages() as $package) {
                 $names = $package->getNames();
                 $stability = $package->getStability();
                 if ($exempt || $this->isPackageAcceptable($names, $stability)) {
                     $package->setId($this->id++);
                     $this->packages[] = $package;
                     foreach ($names as $provided) {
                         $this->packageByName[$provided][] = $package;
                     }
                     // handle root package aliases
                     $name = $package->getName();
                     if (isset($rootAliases[$name][$package->getVersion()])) {
                         $alias = $rootAliases[$name][$package->getVersion()];
                         if ($package instanceof AliasPackage) {
                             $package = $package->getAliasOf();
                         }
                         $aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
                         $aliasPackage->setRootPackageAlias(true);
                         $aliasPackage->setId($this->id++);
                         $package->getRepository()->addPackage($aliasPackage);
                         $this->packages[] = $aliasPackage;
                         foreach ($aliasPackage->getNames() as $name) {
                             $this->packageByName[$name][] = $aliasPackage;
                         }
                     }
                 }
             }
         }
     }
 }
示例#4
0
 private function aliasPackages(PlatformRepository $platformRepo)
 {
     if (!$this->update && $this->locker->isLocked()) {
         $aliases = $this->locker->getAliases();
     } else {
         $aliases = $this->package->getAliases();
     }
     foreach ($aliases as $alias) {
         $packages = array_merge($platformRepo->findPackages($alias['package'], $alias['version']), $this->repositoryManager->findPackages($alias['package'], $alias['version']));
         foreach ($packages as $package) {
             $package->setAlias($alias['alias_normalized']);
             $package->setPrettyAlias($alias['alias']);
             $package->getRepository()->addPackage($aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']));
             $aliasPackage->setRootPackageAlias(true);
         }
     }
     return $aliases;
 }
示例#5
0
 /**
  * Adds a repository and its packages to this package pool
  *
  * @param RepositoryInterface $repo        A package repository
  * @param array               $rootAliases
  */
 public function addRepository(RepositoryInterface $repo, $rootAliases = array())
 {
     if ($repo instanceof CompositeRepository) {
         $repos = $repo->getRepositories();
     } else {
         $repos = array($repo);
     }
     foreach ($repos as $repo) {
         $this->repositories[] = $repo;
         $exempt = $repo instanceof PlatformRepository || $repo instanceof InstalledRepositoryInterface;
         if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
             $this->providerRepos[] = $repo;
             $repo->setRootAliases($rootAliases);
             $repo->resetPackageIds();
         } else {
             foreach ($repo->getPackages() as $package) {
                 $names = $package->getNames();
                 $stability = $package->getStability();
                 if ($exempt || $this->isPackageAcceptable($names, $stability)) {
                     $package->setId($this->id++);
                     $this->packages[] = $package;
                     $this->packageByExactName[$package->getName()][$package->id] = $package;
                     foreach ($names as $provided) {
                         $this->packageByName[$provided][] = $package;
                     }
                     // handle root package aliases
                     $name = $package->getName();
                     if (isset($rootAliases[$name][$package->getVersion()])) {
                         $alias = $rootAliases[$name][$package->getVersion()];
                         if ($package instanceof AliasPackage) {
                             $package = $package->getAliasOf();
                         }
                         $aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
                         $aliasPackage->setRootPackageAlias(true);
                         $aliasPackage->setId($this->id++);
                         $package->getRepository()->addPackage($aliasPackage);
                         $this->packages[] = $aliasPackage;
                         $this->packageByExactName[$aliasPackage->getName()][$aliasPackage->id] = $aliasPackage;
                         foreach ($aliasPackage->getNames() as $name) {
                             $this->packageByName[$name][] = $aliasPackage;
                         }
                     }
                 }
             }
         }
     }
 }