You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.9 KiB
PHTML
148 lines
4.9 KiB
PHTML
6 years ago
|
<?php
|
||
|
|
||
|
/*
|
||
|
* This file is part of Composer.
|
||
|
*
|
||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||
|
*
|
||
|
* For the full copyright and license information, please view the LICENSE
|
||
|
* file that was distributed with this source code.
|
||
|
*/
|
||
|
|
||
|
namespace Composer\DependencyResolver;
|
||
|
|
||
|
use Composer\Package\AliasPackage;
|
||
|
use Composer\Package\BasePackage;
|
||
|
use Composer\Package\PackageInterface;
|
||
|
use Composer\Repository\AsyncRepositoryInterface;
|
||
|
use Composer\Repository\InstalledRepositoryInterface;
|
||
|
use Composer\Repository\LockArrayRepository;
|
||
|
use Composer\Repository\PlatformRepository;
|
||
|
|
||
|
/**
|
||
|
* @author Nils Adermann <naderman@naderman.de>
|
||
|
*/
|
||
|
class PoolBuilder
|
||
|
{
|
||
|
private $isPackageAcceptableCallable;
|
||
|
private $filterRequires;
|
||
|
private $rootAliases;
|
||
|
|
||
|
private $loadedNames = array();
|
||
|
|
||
|
private $id = 1;
|
||
|
private $packages = array();
|
||
|
private $priorities = array();
|
||
|
|
||
|
public function __construct($isPackageAcceptableCallable, array $filterRequires = array())
|
||
|
{
|
||
|
$this->isPackageAcceptableCallable = $isPackageAcceptableCallable;
|
||
|
$this->filterRequires = $filterRequires;
|
||
|
}
|
||
|
|
||
|
public function buildPool(array $repositories, array $rootAliases, Request $request)
|
||
|
{
|
||
|
$this->pool = new Pool($this->filterRequires);
|
||
|
$this->rootAliases = $rootAliases;
|
||
|
|
||
|
// TODO do we really want the request here? kind of want a root requirements thingy instead
|
||
|
$loadNames = array();
|
||
|
foreach ($request->getJobs() as $job) {
|
||
|
switch ($job['cmd']) {
|
||
|
case 'install':
|
||
|
$loadNames[$job['packageName']] = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
foreach ($repositories as $repository) {
|
||
|
if ($repository instanceof ComposerRepository && $repository->hasProviders()) {
|
||
|
$this->providerRepos[] = $repository;
|
||
|
$repository->setRootAliases($this->rootAliases);
|
||
|
$repository->resetPackageIds();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
while (!empty($loadNames)) {
|
||
|
$loadIds = array();
|
||
|
foreach ($repositories as $key => $repository) {
|
||
|
if ($repository instanceof AsyncRepositoryInterface) {
|
||
|
$loadIds[$key] = $repository->requestPackages($loadNames);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
foreach ($loadNames as $name => $void) {
|
||
|
$this->loadedNames[$name] = true;
|
||
|
}
|
||
|
|
||
|
$newLoadNames = array();
|
||
|
foreach ($repositories as $key => $repository) {
|
||
|
if ($repository instanceof PlatformRepository || $repository instanceof InstalledRepositoryInterface) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if ($repository instanceof AsyncRepositoryInterface) {
|
||
|
$packages = $repository->returnPackages($loadIds[$key]);
|
||
|
} else {
|
||
|
$packages = $repository->loadPackages($loadNames);
|
||
|
}
|
||
|
|
||
|
foreach ($packages as $package) {
|
||
|
if (call_user_func($this->isPackageAcceptableCallable, $package->getNames(), $package->getStability())) {
|
||
|
$newLoadNames += $this->loadPackage($package, $key);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$loadNames = $newLoadNames;
|
||
|
}
|
||
|
|
||
|
foreach ($repositories as $key => $repository) {
|
||
|
if ($repository instanceof PlatformRepository ||
|
||
|
$repository instanceof InstalledRepositoryInterface) {
|
||
|
foreach ($repository->getPackages() as $package) {
|
||
|
$this->loadPackage($package, $key);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$this->pool->setPackages($this->packages, $this->priorities);
|
||
|
|
||
|
return $this->pool;
|
||
|
}
|
||
|
|
||
|
private function loadPackage(PackageInterface $package, $repoIndex)
|
||
|
{
|
||
|
$package->setId($this->id++);
|
||
|
$this->packages[] = $package;
|
||
|
$this->priorities[$this->id - 2] = -$repoIndex;
|
||
|
|
||
|
// handle root package aliases
|
||
|
$name = $package->getName();
|
||
|
if (isset($this->rootAliases[$name][$package->getVersion()])) {
|
||
|
$alias = $this->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); // TODO do we need this?
|
||
|
$this->packages[] = $aliasPackage;
|
||
|
}
|
||
|
|
||
|
$loadNames = array();
|
||
|
foreach ($package->getRequires() as $link) {
|
||
|
$require = $link->getTarget();
|
||
|
if (!isset($this->loadedNames[$require])) {
|
||
|
$loadNames[$require] = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $loadNames;
|
||
|
}
|
||
|
}
|
||
|
|