Debian Codegraph @

vendor/ipl/validator/src/HostnameValidator.php

raw
1 <?php
2
3 namespace ipl\Validator;
4
5 /**
6 * Validate a hostname
7 */
8 class HostnameValidator extends BaseValidator
9 {
10 /**
11 * Check whether the value is a valid hostname per RFC 1034, RFC 1035, RFC 952, RFC 1123, RFC 2732, RFC 2181
12 *
13 * @param string $value
14 *
15 * @return bool
16 */
17 public function isValid($value): bool
18 {
19 $this->clearMessages();
20
21 $asciiHostname = idn_to_ascii($value, 0, INTL_IDNA_VARIANT_UTS46);
22 if (filter_var($asciiHostname, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false) {
23 $this->addMessage(sprintf(
24 $this->translate("%s is not a valid host name."),
25 $value
26 ));
27
28 return false;
29 }
30
31 return true;
32 }
33 }