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

Breadcrumb

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

function NoProxyPattern::splitHostPort

Splits the hostname into host and port components

Return value

mixed[] host, port, if there was error

2 calls to NoProxyPattern::splitHostPort()
NoProxyPattern::getRule in vendor/composer/composer/src/Composer/Util/NoProxyPattern.php
Finds or creates rule data for a hostname
NoProxyPattern::getUrlData in vendor/composer/composer/src/Composer/Util/NoProxyPattern.php
Returns false is the url cannot be parsed, otherwise a data object

File

vendor/composer/composer/src/Composer/Util/NoProxyPattern.php, line 357

Class

NoProxyPattern
Tests URLs against NO_PROXY patterns

Namespace

Composer\Util

Code

private function splitHostPort(string $hostName) : array {
    // host, port, err
    $error = [
        '',
        '',
        true,
    ];
    $port = 0;
    $ip6 = '';
    // Check for square-bracket notation
    if ($hostName[0] === '[') {
        $index = strpos($hostName, ']');
        // The smallest ip6 address is ::
        if (false === $index || $index < 3) {
            return $error;
        }
        $ip6 = substr($hostName, 1, $index - 1);
        $hostName = substr($hostName, $index + 1);
        if (strpbrk($hostName, '[]') !== false || substr_count($hostName, ':') > 1) {
            return $error;
        }
    }
    if (substr_count($hostName, ':') === 1) {
        $index = strpos($hostName, ':');
        $port = substr($hostName, $index + 1);
        $hostName = substr($hostName, 0, $index);
        if (!$this->validateInt($port, 1, 65535)) {
            return $error;
        }
        $port = (int) $port;
    }
    $host = $ip6 . $hostName;
    return [
        $host,
        $port,
        false,
    ];
}

API Navigation

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