isValid($value)) { throw new \InvalidArgumentException(\sprintf('Invalid NSID "%s".', $value)); } $parts = \explode('.', $value); $name = \array_pop($parts); $authority = \strtolower(\implode('.', $parts)); return new Nsid($authority . '.' . $name, $authority, $name); } /** * Returns whether the value is a valid NSID. */ public static function isValid(string $value): bool { if ($value === '' || \strlen($value) > self::MAX_LENGTH) { return FALSE; } return ( \preg_match( '/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)$/', $value, ) === 1 ); } /** * Returns the normalized supplied value. */ public function normalize(string $value): string { return $this->parse($value)->value; } }