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

Breadcrumb

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

function Factory::createHttpDownloader

If you are calling this in a plugin, you probably should instead use $composer->getLoop()->getHttpDownloader()

Parameters

IOInterface $io IO instance:

Config $config Config instance:

mixed[] $options Array of options passed directly to HttpDownloader constructor:

10 calls to Factory::createHttpDownloader()
ArchiveCommand::archive in vendor/composer/composer/src/Composer/Command/ArchiveCommand.php
Bitbucket::__construct in vendor/composer/composer/src/Composer/Util/Bitbucket.php
Constructor.
DiagnoseCommand::execute in vendor/composer/composer/src/Composer/Command/DiagnoseCommand.php
Executes the current command.
Factory::createComposer in vendor/composer/composer/src/Composer/Factory.php
Creates a Composer instance
GitHub::__construct in vendor/composer/composer/src/Composer/Util/GitHub.php
Constructor.

... See full list

File

vendor/composer/composer/src/Composer/Factory.php, line 639

Class

Factory
Creates a configured instance of composer.

Namespace

Composer

Code

public static function createHttpDownloader(IOInterface $io, Config $config, array $options = []) : HttpDownloader {
    static $warned = false;
    $disableTls = false;
    // allow running the config command if disable-tls is in the arg list, even if openssl is missing, to allow disabling it via the config command
    if (isset($_SERVER['argv']) && in_array('disable-tls', $_SERVER['argv']) && (in_array('conf', $_SERVER['argv']) || in_array('config', $_SERVER['argv']))) {
        $warned = true;
        $disableTls = !extension_loaded('openssl');
    }
    elseif ($config->get('disable-tls') === true) {
        if (!$warned) {
            $io->writeError('<warning>You are running Composer with SSL/TLS protection disabled.</warning>');
        }
        $warned = true;
        $disableTls = true;
    }
    elseif (!extension_loaded('openssl')) {
        throw new Exception\NoSslException('The openssl extension is required for SSL/TLS protection but is not available. ' . 'If you can not enable the openssl extension, you can disable this error, at your own risk, by setting the \'disable-tls\' option to true.');
    }
    $httpDownloaderOptions = [];
    if ($disableTls === false) {
        if ('' !== $config->get('cafile')) {
            $httpDownloaderOptions['ssl']['cafile'] = $config->get('cafile');
        }
        if ('' !== $config->get('capath')) {
            $httpDownloaderOptions['ssl']['capath'] = $config->get('capath');
        }
        $httpDownloaderOptions = array_replace_recursive($httpDownloaderOptions, $options);
    }
    try {
        $httpDownloader = new HttpDownloader($io, $config, $httpDownloaderOptions, $disableTls);
    } catch (TransportException $e) {
        if (false !== strpos($e->getMessage(), 'cafile')) {
            $io->write('<error>Unable to locate a valid CA certificate file. You must set a valid \'cafile\' option.</error>');
            $io->write('<error>A valid CA certificate file is required for SSL/TLS protection.</error>');
            $io->write('<error>You can disable this error, at your own risk, by setting the \'disable-tls\' option to true.</error>');
        }
        throw $e;
    }
    return $httpDownloader;
}

API Navigation

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