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

Breadcrumb

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

function Utils::idnUriConvert

@internal

Throws

InvalidArgumentException

2 calls to Utils::idnUriConvert()
Client::buildUri in vendor/guzzlehttp/guzzle/src/Client.php
RedirectMiddleware::modifyRequest in vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php

File

vendor/guzzlehttp/guzzle/src/Utils.php, line 323

Class

Utils

Namespace

GuzzleHttp

Code

public static function idnUriConvert(UriInterface $uri, int $options = 0) : UriInterface {
    if ($uri->getHost()) {
        $asciiHost = self::idnToAsci($uri->getHost(), $options, $info);
        if ($asciiHost === false) {
            $errorBitSet = $info['errors'] ?? 0;
            $errorConstants = array_filter(array_keys(get_defined_constants()), static function (string $name) : bool {
                return substr($name, 0, 11) === 'IDNA_ERROR_';
            });
            $errors = [];
            foreach ($errorConstants as $errorConstant) {
                if ($errorBitSet & constant($errorConstant)) {
                    $errors[] = $errorConstant;
                }
            }
            $errorMessage = 'IDN conversion failed';
            if ($errors) {
                $errorMessage .= ' (errors: ' . implode(', ', $errors) . ')';
            }
            throw new InvalidArgumentException($errorMessage);
        }
        if ($uri->getHost() !== $asciiHost) {
            // Replace URI only if the ASCII version is different
            $uri = $uri->withHost($asciiHost);
        }
    }
    return $uri;
}

API Navigation

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