Esempio n. 1
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;
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
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;
                         }
                     }
                 }
             }
         }
     }
 }