1
0
Fork 0

Allow restricting allowed types as well, and allow configured ignored/allowed types in Installer class

pull/11922/head
Jordi Boggiano 2024-04-02 17:38:41 +02:00
parent b12a88b7f3
commit 94be5b5c14
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 50 additions and 8 deletions

View File

@ -108,6 +108,8 @@ class PoolBuilder
private $skippedLoad = []; private $skippedLoad = [];
/** @var list<string> */ /** @var list<string> */
private $ignoredTypes = []; private $ignoredTypes = [];
/** @var list<string>|null */
private $allowedTypes = null;
/** /**
* If provided, only these package names are loaded * If provided, only these package names are loaded
@ -173,6 +175,8 @@ class PoolBuilder
} }
/** /**
* Packages of those types are ignored
*
* @param list<string> $types * @param list<string> $types
*/ */
public function setIgnoredTypes(array $types): void public function setIgnoredTypes(array $types): void
@ -180,6 +184,16 @@ class PoolBuilder
$this->ignoredTypes = $types; $this->ignoredTypes = $types;
} }
/**
* Only packages of those types are allowed if set to non-null
*
* @param list<string>|null $types
*/
public function setAllowedTypes(?array $types): void
{
$this->allowedTypes = $types;
}
/** /**
* @param RepositoryInterface[] $repositories * @param RepositoryInterface[] $repositories
*/ */
@ -416,6 +430,10 @@ class PoolBuilder
} }
foreach ($result['packages'] as $package) { foreach ($result['packages'] as $package) {
$this->loadedPerRepo[$repoIndex][$package->getName()][$package->getVersion()] = $package; $this->loadedPerRepo[$repoIndex][$package->getName()][$package->getVersion()] = $package;
if (in_array($package->getType(), $this->ignoredTypes, true) || ($this->allowedTypes !== null && !in_array($package->getType(), $this->allowedTypes, true))) {
continue;
}
$this->loadPackage($request, $repositories, $package, !isset($this->pathRepoUnlocked[$package->getName()])); $this->loadPackage($request, $repositories, $package, !isset($this->pathRepoUnlocked[$package->getName()]));
} }
} }
@ -426,10 +444,6 @@ class PoolBuilder
*/ */
private function loadPackage(Request $request, array $repositories, BasePackage $package, bool $propagateUpdate): void private function loadPackage(Request $request, array $repositories, BasePackage $package, bool $propagateUpdate): void
{ {
if (in_array($package->getType(), $this->ignoredTypes, true)) {
return;
}
$index = $this->indexCounter++; $index = $this->indexCounter++;
$this->packages[$index] = $package; $this->packages[$index] = $package;

View File

@ -176,6 +176,10 @@ class Installer
protected $errorOnAudit = false; protected $errorOnAudit = false;
/** @var Auditor::FORMAT_* */ /** @var Auditor::FORMAT_* */
protected $auditFormat = Auditor::FORMAT_SUMMARY; protected $auditFormat = Auditor::FORMAT_SUMMARY;
/** @var list<string> */
private $ignoredTypes = ['php-ext', 'php-ext-zend'];
/** @var list<string>|null */
private $allowedTypes = null;
/** @var bool */ /** @var bool */
protected $updateMirrors = false; protected $updateMirrors = false;
@ -492,7 +496,7 @@ class Installer
$request->setUpdateAllowList($this->updateAllowList, $this->updateAllowTransitiveDependencies); $request->setUpdateAllowList($this->updateAllowList, $this->updateAllowTransitiveDependencies);
} }
$pool = $repositorySet->createPool($request, $this->io, $this->eventDispatcher, $this->createPoolOptimizer($policy)); $pool = $repositorySet->createPool($request, $this->io, $this->eventDispatcher, $this->createPoolOptimizer($policy), $this->ignoredTypes, $this->allowedTypes);
$this->io->writeError('<info>Updating dependencies</info>'); $this->io->writeError('<info>Updating dependencies</info>');
@ -750,7 +754,7 @@ class Installer
$request->requireName($link->getTarget(), $link->getConstraint()); $request->requireName($link->getTarget(), $link->getConstraint());
} }
$pool = $repositorySet->createPool($request, $this->io, $this->eventDispatcher); $pool = $repositorySet->createPool($request, $this->io, $this->eventDispatcher, null, $this->ignoredTypes, $this->allowedTypes);
// solve dependencies // solve dependencies
$solver = new Solver($policy, $pool, $this->io); $solver = new Solver($policy, $pool, $this->io);
@ -1103,6 +1107,26 @@ class Installer
); );
} }
/**
* Packages of those types are ignored, by default php-ext and php-ext-zend are ignored
*
* @param list<string> $types
*/
public function setIgnoredTypes(array $types): void
{
$this->ignoredTypes = $types;
}
/**
* Only packages of those types are allowed if set to non-null
*
* @param list<string>|null $types
*/
public function setAllowedTypes(?array $types): void
{
$this->allowedTypes = $types;
}
/** /**
* @return $this * @return $this
*/ */

View File

@ -310,11 +310,15 @@ class RepositorySet
/** /**
* Create a pool for dependency resolution from the packages in this repository set. * Create a pool for dependency resolution from the packages in this repository set.
*
* @param list<string> $ignoredTypes Packages of those types are ignored
* @param list<string>|null $allowedTypes Only packages of those types are allowed if set to non-null
*/ */
public function createPool(Request $request, IOInterface $io, ?EventDispatcher $eventDispatcher = null, ?PoolOptimizer $poolOptimizer = null): Pool public function createPool(Request $request, IOInterface $io, ?EventDispatcher $eventDispatcher = null, ?PoolOptimizer $poolOptimizer = null, array $ignoredTypes = [], ?array $allowedTypes = null): Pool
{ {
$poolBuilder = new PoolBuilder($this->acceptableStabilities, $this->stabilityFlags, $this->rootAliases, $this->rootReferences, $io, $eventDispatcher, $poolOptimizer, $this->temporaryConstraints); $poolBuilder = new PoolBuilder($this->acceptableStabilities, $this->stabilityFlags, $this->rootAliases, $this->rootReferences, $io, $eventDispatcher, $poolOptimizer, $this->temporaryConstraints);
$poolBuilder->setIgnoredTypes(['php-ext', 'php-ext-zend']); $poolBuilder->setIgnoredTypes($ignoredTypes);
$poolBuilder->setAllowedTypes($allowedTypes);
foreach ($this->repositories as $repo) { foreach ($this->repositories as $repo) {
if (($repo instanceof InstalledRepositoryInterface || $repo instanceof InstalledRepository) && !$this->allowInstalledRepositories) { if (($repo instanceof InstalledRepositoryInterface || $repo instanceof InstalledRepository) && !$this->allowInstalledRepositories) {