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

Breadcrumb

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

function ProxyItem::__construct

Parameters

string $proxyUrl The value from the environment:

string $envName The name of the environment variable:

Throws

\RuntimeException If the proxy url is invalid

File

vendor/composer/composer/src/Composer/Util/Http/ProxyItem.php, line 37

Class

ProxyItem
@internal @author John Stevenson <john-stevenson@blueyonder.co.uk>

Namespace

Composer\Util\Http

Code

public function __construct(string $proxyUrl, string $envName) {
    $syntaxError = sprintf('unsupported `%s` syntax', $envName);
    if (strpbrk($proxyUrl, "\r\n\t") !== false) {
        throw new \RuntimeException($syntaxError);
    }
    if (false === ($proxy = parse_url($proxyUrl))) {
        throw new \RuntimeException($syntaxError);
    }
    if (!isset($proxy['host'])) {
        throw new \RuntimeException('unable to find proxy host in ' . $envName);
    }
    $scheme = isset($proxy['scheme']) ? strtolower($proxy['scheme']) . '://' : 'http://';
    $safe = '';
    if (isset($proxy['user'])) {
        $safe = '***';
        $user = $proxy['user'];
        $auth = rawurldecode($proxy['user']);
        if (isset($proxy['pass'])) {
            $safe .= ':***';
            $user .= ':' . $proxy['pass'];
            $auth .= ':' . rawurldecode($proxy['pass']);
        }
        $safe .= '@';
        if (strlen($user) > 0) {
            $this->curlAuth = $user;
            $this->optionsAuth = 'Proxy-Authorization: Basic ' . base64_encode($auth);
        }
    }
    $host = $proxy['host'];
    $port = null;
    if (isset($proxy['port'])) {
        $port = $proxy['port'];
    }
    elseif ($scheme === 'http://') {
        $port = 80;
    }
    elseif ($scheme === 'https://') {
        $port = 443;
    }
    // We need a port because curl uses 1080 for http. Port 0 is reserved,
    // but is considered valid depending on the PHP or Curl version.
    if ($port === null) {
        throw new \RuntimeException('unable to find proxy port in ' . $envName);
    }
    if ($port === 0) {
        throw new \RuntimeException('port 0 is reserved in ' . $envName);
    }
    $this->url = sprintf('%s%s:%d', $scheme, $host, $port);
    $this->safeUrl = sprintf('%s%s%s:%d', $scheme, $safe, $host, $port);
    $scheme = str_replace([
        'http://',
        'https://',
    ], [
        'tcp://',
        'ssl://',
    ], $scheme);
    $this->optionsProxy = sprintf('%s%s:%d', $scheme, $host, $port);
}

API Navigation

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