function Utils::idnUriConvert
@internal
Throws
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
Namespace
GuzzleHttpCode
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;
}