normalizeInput($value); if (!$this->isValid($normalized)) { throw new \InvalidArgumentException(\sprintf('Invalid handle "%s".', $value)); } return new Handle($normalized, \explode('.', $normalized)); } /** * Returns whether the value is a valid handle. */ public function isValid(string $value): bool { $normalized = $this->normalizeInput($value); if ($normalized === '' || \strlen($normalized) > self::MAX_LENGTH) { return FALSE; } return ( \preg_match( '/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/', $normalized, ) === 1 ); } /** * Returns whether the handle syntax is eligible for resolution. */ public function isResolvableSyntax(string $value, bool $allow_test_tld = FALSE): bool { if (!$this->isValid($value)) { return FALSE; } $labels = \explode('.', $this->normalizeInput($value)); $tld = \end($labels); if ($tld === 'test') { return $allow_test_tld; } return !\in_array($tld, self::DISALLOWED_RESOLUTION_TLDS, TRUE); } /** * Returns the normalized supplied value. */ public function normalize(string $value): string { return $this->parse($value)->value; } private static function normalizeInput(string $value): string { return \strtolower($value); } }