* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace League\Uri; use BackedEnum; use Exception; use JsonSerializable; use League\Uri\Contracts\UriComponentInterface; use League\Uri\Exceptions\SyntaxError; use League\Uri\Idna\Converter as IdnConverter; use Stringable; use Throwable; use function array_key_first; use function count; use function explode; use function filter_var; use function get_object_vars; use function in_array; use function inet_pton; use function is_object; use function preg_match; use function rawurldecode; use function strpos; use function strtolower; use function substr; use const FILTER_FLAG_IPV4; use const FILTER_FLAG_IPV6; use const FILTER_VALIDATE_IP; /** * @phpstan-type HostRecordSerializedShape array{0: array{host: ?string}, 1: array{}} */ final class HostRecord implements JsonSerializable { /** * Maximum number of host cached. * * @var int */ private const MAXIMUM_HOST_CACHED = 100; private const REGEXP_NON_ASCII_PATTERN = '/[^\x20-\x7f]/'; /** * @see https://tools.ietf.org/html/rfc3986#section-3.2.2 * * invalid characters in host regular expression */ private const REGEXP_INVALID_HOST_CHARS = '/ [:\/?#\[\]@ ] # gen-delims characters as well as the space character /ix'; /** * General registered name regular expression. * * @see https://tools.ietf.org/html/rfc3986#section-3.2.2 * @see https://regex101.com/r/fptU8V/1 */ private const REGEXP_REGISTERED_NAME = '/ (?(DEFINE) (?[a-z0-9_~\-]) # . is missing as it is used to separate labels (?[!$&\'()*+,;=]) (?%[A-F0-9]{2}) (?(?:(?&unreserved)|(?&sub_delims)|(?&encoded))*) ) ^(?:(?®_name)\.)*(?®_name)\.?$ /ix'; /** * Domain name regular expression. * * Everything but the domain name length is validated * * @see https://tools.ietf.org/html/rfc1034#section-3.5 * @see https://tools.ietf.org/html/rfc1123#section-2.1 * @see https://regex101.com/r/71j6rt/1 */ private const REGEXP_DOMAIN_NAME = '/ (?(DEFINE) (? [a-z0-9]) # alpha digit (? [a-z0-9-]) # alpha digit and hyphen (? (?&let_dig_hyp){0,61}(?&let_dig)) # domain label end (?