Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RepositorySet.php

function RepositorySet::findPackages

Find packages providing or matching a name and optionally meeting a constraint in all repositories

Returned in the order of repositories, matching priority

Parameters

int $flags any of the ALLOW_* constants from this class to tweak what is returned:

Return value

BasePackage[]

File

vendor/composer/composer/src/Composer/Repository/RepositorySet.php, line 187

Class

RepositorySet
@author Nils Adermann <naderman@naderman.de>

Namespace

Composer\Repository

Code

public function findPackages(string $name, ?ConstraintInterface $constraint = null, int $flags = 0) : array {
    $ignoreStability = ($flags & self::ALLOW_UNACCEPTABLE_STABILITIES) !== 0;
    $loadFromAllRepos = ($flags & self::ALLOW_SHADOWED_REPOSITORIES) !== 0;
    $packages = [];
    if ($loadFromAllRepos) {
        foreach ($this->repositories as $repository) {
            $packages[] = $repository->findPackages($name, $constraint) ?: [];
        }
    }
    else {
        foreach ($this->repositories as $repository) {
            $result = $repository->loadPackages([
                $name => $constraint,
            ], $ignoreStability ? BasePackage::STABILITIES : $this->acceptableStabilities, $ignoreStability ? [] : $this->stabilityFlags);
            $packages[] = $result['packages'];
            foreach ($result['namesFound'] as $nameFound) {
                // avoid loading the same package again from other repositories once it has been found
                if ($name === $nameFound) {
                    break 2;
                }
            }
        }
    }
    $candidates = $packages ? array_merge(...$packages) : [];
    // when using loadPackages above (!$loadFromAllRepos) the repos already filter for stability so no need to do it again
    if ($ignoreStability || !$loadFromAllRepos) {
        return $candidates;
    }
    $result = [];
    foreach ($candidates as $candidate) {
        if ($this->isPackageAcceptable($candidate->getNames(), $candidate->getStability())) {
            $result[] = $candidate;
        }
    }
    return $result;
}
RSS feed
Powered by Drupal