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

Breadcrumb

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

function ComposerRepository::__construct

@phpstan-param array{url: non-empty-string, options?: mixed[], type?: 'composer', allow_ssl_downgrade?: bool} $repoConfig

Parameters

array<string, mixed> $repoConfig:

Overrides ArrayRepository::__construct

File

vendor/composer/composer/src/Composer/Repository/ComposerRepository.php, line 138

Class

ComposerRepository
@author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\Repository

Code

public function __construct(array $repoConfig, IOInterface $io, Config $config, HttpDownloader $httpDownloader, ?EventDispatcher $eventDispatcher = null) {
    parent::__construct();
    if (!Preg::isMatch('{^[\\w.]+\\??://}', $repoConfig['url'])) {
        if (($localFilePath = realpath($repoConfig['url'])) !== false) {
            // it is a local path, add file scheme
            $repoConfig['url'] = 'file://' . $localFilePath;
        }
        else {
            // otherwise, assume http as the default protocol
            $repoConfig['url'] = 'http://' . $repoConfig['url'];
        }
    }
    $repoConfig['url'] = rtrim($repoConfig['url'], '/');
    if ($repoConfig['url'] === '') {
        throw new \InvalidArgumentException('The repository url must not be an empty string');
    }
    if (str_starts_with($repoConfig['url'], 'https?')) {
        $repoConfig['url'] = (extension_loaded('openssl') ? 'https' : 'http') . substr($repoConfig['url'], 6);
    }
    $urlBits = parse_url(strtr($repoConfig['url'], '\\', '/'));
    if ($urlBits === false || empty($urlBits['scheme'])) {
        throw new \UnexpectedValueException('Invalid url given for Composer repository: ' . $repoConfig['url']);
    }
    if (!isset($repoConfig['options'])) {
        $repoConfig['options'] = [];
    }
    if (isset($repoConfig['allow_ssl_downgrade']) && true === $repoConfig['allow_ssl_downgrade']) {
        $this->allowSslDowngrade = true;
    }
    $this->options = $repoConfig['options'];
    $this->url = $repoConfig['url'];
    // force url for packagist.org to repo.packagist.org
    if (Preg::isMatch('{^(?P<proto>https?)://packagist\\.org/?$}i', $this->url, $match)) {
        $this->url = $match['proto'] . '://repo.packagist.org';
    }
    $baseUrl = rtrim(Preg::replace('{(?:/[^/\\\\]+\\.json)?(?:[?#].*)?$}', '', $this->url), '/');
    assert($baseUrl !== '');
    $this->baseUrl = $baseUrl;
    $this->io = $io;
    $this->cache = new Cache($io, $config->get('cache-repo-dir') . '/' . Preg::replace('{[^a-z0-9.]}i', '-', Url::sanitize($this->url)), 'a-z0-9.$~_');
    $this->cache
        ->setReadOnly($config->get('cache-read-only'));
    $this->versionParser = new VersionParser();
    $this->loader = new ArrayLoader($this->versionParser);
    $this->httpDownloader = $httpDownloader;
    $this->eventDispatcher = $eventDispatcher;
    $this->repoConfig = $repoConfig;
    $this->loop = new Loop($this->httpDownloader);
}
RSS feed
Powered by Drupal