resolve($name, $options); } /** * Query specific DNS records. * * @param string $name Unlike resolve(), query() allows for requesting _any_ name (as DNS RFC allows for arbitrary * strings) * @param int|int[] $type Use constants of Amp\Dns\Record * @param array $options @see resolve documentation * * @return \Amp\Promise */ function query(string $name, $type, array $options = []): Promise { return resolver()->query($name, $type, $options); } /** * Checks whether a string is a valid DNS name. * * @param string $name DNS name to check. * * @return bool */ function isValidHostName(string $name): bool { static $pattern = '/^(?[a-z0-9]([a-z0-9-]*[a-z0-9])?)(\.(?&name))*$/i'; return !isset($name[253]) && \preg_match($pattern, $name); } if (\function_exists('idn_to_ascii')) { /** * Normalizes a DNS name. * * @param string $label DNS name. * * @return string Normalized DNS name. * * @throws \Error If an invalid name or an IDN name without ext/intl being installed has been passed. */ function normalizeName(string $label): string { if (false === $result = \idn_to_ascii($label, 0, INTL_IDNA_VARIANT_UTS46)) { throw new InvalidNameError("Label '{$label}' could not be processed for IDN"); } return $result; } } else { function normalizeName(string $label): string { if (\preg_match('/[\x80-\xff]/', $label)) { throw new InvalidNameError( "Label '{$label}' contains non-ASCII characters and IDN support is not available." . " Verify that ext/intl is installed for IDN support." ); } return \strtolower($label); } }