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

Breadcrumb

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

function NoProxyPattern::ipCheckData

Creates an object containing IP data if the host is an IP address

Parameters

null|stdClass $ipdata Set by method if IP address found:

bool $allowPrefix Whether a CIDR prefix-length is expected:

Return value

bool False if the host contains invalid data

2 calls to NoProxyPattern::ipCheckData()
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 195

Class

NoProxyPattern
Tests URLs against NO_PROXY patterns

Namespace

Composer\Util

Code

private function ipCheckData(string $host, ?stdClass &$ipdata, bool $allowPrefix = false) : bool {
    $ipdata = null;
    $netmask = null;
    $prefix = null;
    $modified = false;
    // Check for a CIDR prefix-length
    if (strpos($host, '/') !== false) {
        [
            $host,
            $prefix,
        ] = explode('/', $host);
        if (!$allowPrefix || !$this->validateInt($prefix, 0, 128)) {
            return false;
        }
        $prefix = (int) $prefix;
        $modified = true;
    }
    // See if this is an ip address
    if (!filter_var($host, FILTER_VALIDATE_IP)) {
        return !$modified;
    }
    [
        $ip,
        $size,
    ] = $this->ipGetAddr($host);
    if ($prefix !== null) {
        // Check for a valid prefix
        if ($prefix > $size * 8) {
            return false;
        }
        [
            $ip,
            $netmask,
        ] = $this->ipGetNetwork($ip, $size, $prefix);
    }
    $ipdata = $this->makeIpData($ip, $size, $netmask);
    return true;
}

API Navigation

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