isValid($value)) { throw new \InvalidArgumentException(\sprintf('Invalid DID "%s".', $value)); } [, $method, $identifier] = \explode(':', $value, 3); return new Did($value, $method, $identifier, \in_array($method, ['plc', 'web'], TRUE)); } /** * Returns whether the value is a valid DID. */ public static function isValid(string $value): bool { if ($value === '' || \strlen($value) > self::MAX_LENGTH) { return FALSE; } if (\str_contains($value, '?') || \str_contains($value, '#') || \str_contains($value, '/')) { return FALSE; } if (\preg_match('/%(?![0-9A-Fa-f]{2})/', $value) === 1) { return FALSE; } return \preg_match('/^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$/', $value) === 1; } /** * Returns whether the DID method can be resolved by this library. */ public function isSupported(string $value): bool { return $this->parse($value)->supported; } /** * Returns the normalized supplied value. */ public function normalize(string $value): string { return $this->parse($value)->value; } }