rawurldecode($matches[0]), $encoded ); if (1 !== preg_match('//u', $decoded)) { throw new SyntaxError('The display string '.$encoded.' contains invalid characters.'); } return new self($decoded); } /** * Returns a new instance from a raw decoded string. */ public static function fromDecoded(Stringable|string $decoded): self { return new self((string) $decoded); } /** * Returns the decoded string. */ public function decoded(): string { return $this->value; } /** * Returns the base64 encoded string. */ public function encoded(): string { return (string) preg_replace_callback( '/[%"\x00-\x1F\x7F-\xFF]/', static fn (array $matches): string => strtolower(rawurlencode($matches[0])), $this->value ); } public function equals(mixed $other): bool { return $other instanceof self && $other->value === $this->value; } public function type(): Type { return Type::DisplayString; } }