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

Breadcrumb

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

class RepositoryManager

Repositories manager.

@author Jordi Boggiano <j.boggiano@seld.be> @author Konstantin Kudryashov <ever.zet@gmail.com> @author François Pluchino <francois.pluchino@opendisplay.com>

Hierarchy

  • class \Composer\Repository\RepositoryManager

Expanded class hierarchy of RepositoryManager

4 files declare their use of RepositoryManager
Factory.php in vendor/composer/composer/src/Composer/Factory.php
Installer.php in vendor/composer/composer/src/Composer/Installer.php
PartialComposer.php in vendor/composer/composer/src/Composer/PartialComposer.php
RootPackageLoader.php in vendor/composer/composer/src/Composer/Package/Loader/RootPackageLoader.php

File

vendor/composer/composer/src/Composer/Repository/RepositoryManager.php, line 29

Namespace

Composer\Repository
View source
class RepositoryManager {
    
    /** @var InstalledRepositoryInterface */
    private $localRepository;
    
    /** @var list<RepositoryInterface> */
    private $repositories = [];
    
    /** @var array<string, class-string<RepositoryInterface>> */
    private $repositoryClasses = [];
    
    /** @var IOInterface */
    private $io;
    
    /** @var Config */
    private $config;
    
    /** @var HttpDownloader */
    private $httpDownloader;
    
    /** @var ?EventDispatcher */
    private $eventDispatcher;
    
    /** @var ProcessExecutor */
    private $process;
    public function __construct(IOInterface $io, Config $config, HttpDownloader $httpDownloader, ?EventDispatcher $eventDispatcher = null, ?ProcessExecutor $process = null) {
        $this->io = $io;
        $this->config = $config;
        $this->httpDownloader = $httpDownloader;
        $this->eventDispatcher = $eventDispatcher;
        $this->process = $process ?? new ProcessExecutor($io);
    }
    
    /**
     * Searches for a package by its name and version in managed repositories.
     *
     * @param string                                                 $name       package name
     * @param string|\Composer\Semver\Constraint\ConstraintInterface $constraint package version or version constraint to match against
     */
    public function findPackage(string $name, $constraint) : ?PackageInterface {
        foreach ($this->repositories as $repository) {
            
            /** @var RepositoryInterface $repository */
            if ($package = $repository->findPackage($name, $constraint)) {
                return $package;
            }
        }
        return null;
    }
    
    /**
     * Searches for all packages matching a name and optionally a version in managed repositories.
     *
     * @param string                                                 $name       package name
     * @param string|\Composer\Semver\Constraint\ConstraintInterface $constraint package version or version constraint to match against
     *
     * @return PackageInterface[]
     */
    public function findPackages(string $name, $constraint) : array {
        $packages = [];
        foreach ($this->getRepositories() as $repository) {
            $packages = array_merge($packages, $repository->findPackages($name, $constraint));
        }
        return $packages;
    }
    
    /**
     * Adds repository
     *
     * @param RepositoryInterface $repository repository instance
     */
    public function addRepository(RepositoryInterface $repository) : void {
        $this->repositories[] = $repository;
    }
    
    /**
     * Adds a repository to the beginning of the chain
     *
     * This is useful when injecting additional repositories that should trump Packagist, e.g. from a plugin.
     *
     * @param RepositoryInterface $repository repository instance
     */
    public function prependRepository(RepositoryInterface $repository) : void {
        array_unshift($this->repositories, $repository);
    }
    
    /**
     * Returns a new repository for a specific installation type.
     *
     * @param  string                    $type   repository type
     * @param  array<string, mixed>      $config repository configuration
     * @param  string                    $name   repository name
     * @throws \InvalidArgumentException if repository for provided type is not registered
     */
    public function createRepository(string $type, array $config, ?string $name = null) : RepositoryInterface {
        if (!isset($this->repositoryClasses[$type])) {
            throw new \InvalidArgumentException('Repository type is not registered: ' . $type);
        }
        if (isset($config['packagist']) && false === $config['packagist']) {
            $this->io
                ->writeError('<warning>Repository "' . $name . '" (' . json_encode($config) . ') has a packagist key which should be in its own repository definition</warning>');
        }
        $class = $this->repositoryClasses[$type];
        if (isset($config['only']) || isset($config['exclude']) || isset($config['canonical'])) {
            $filterConfig = $config;
            unset($config['only'], $config['exclude'], $config['canonical']);
        }
        $repository = new $class($config, $this->io, $this->config, $this->httpDownloader, $this->eventDispatcher, $this->process);
        if (isset($filterConfig)) {
            $repository = new FilterRepository($repository, $filterConfig);
        }
        return $repository;
    }
    
    /**
     * Stores repository class for a specific installation type.
     *
     * @param string $type  installation type
     * @param class-string<RepositoryInterface> $class class name of the repo implementation
     */
    public function setRepositoryClass(string $type, $class) : void {
        $this->repositoryClasses[$type] = $class;
    }
    
    /**
     * Returns all repositories, except local one.
     *
     * @return RepositoryInterface[]
     */
    public function getRepositories() : array {
        return $this->repositories;
    }
    
    /**
     * Sets local repository for the project.
     *
     * @param InstalledRepositoryInterface $repository repository instance
     */
    public function setLocalRepository(InstalledRepositoryInterface $repository) : void {
        $this->localRepository = $repository;
    }
    
    /**
     * Returns local repository for the project.
     */
    public function getLocalRepository() : InstalledRepositoryInterface {
        return $this->localRepository;
    }

}

Members

Title Sort descending Modifiers Object type Summary
RepositoryManager::$config private property @var Config
RepositoryManager::$eventDispatcher private property @var ?EventDispatcher
RepositoryManager::$httpDownloader private property @var HttpDownloader
RepositoryManager::$io private property @var IOInterface
RepositoryManager::$localRepository private property @var InstalledRepositoryInterface
RepositoryManager::$process private property @var ProcessExecutor
RepositoryManager::$repositories private property @var list&lt;RepositoryInterface&gt;
RepositoryManager::$repositoryClasses private property @var array&lt;string, class-string&lt;RepositoryInterface&gt;&gt;
RepositoryManager::addRepository public function Adds repository
RepositoryManager::createRepository public function Returns a new repository for a specific installation type.
RepositoryManager::findPackage public function Searches for a package by its name and version in managed repositories.
RepositoryManager::findPackages public function Searches for all packages matching a name and optionally a version in managed repositories.
RepositoryManager::getLocalRepository public function Returns local repository for the project.
RepositoryManager::getRepositories public function Returns all repositories, except local one.
RepositoryManager::prependRepository public function Adds a repository to the beginning of the chain
RepositoryManager::setLocalRepository public function Sets local repository for the project.
RepositoryManager::setRepositoryClass public function Stores repository class for a specific installation type.
RepositoryManager::__construct public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal