From 23610b8d49d7c6339cd25f53c9c340d5f3637756 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Mon, 7 Sep 2026 16:10:05 +0200 Subject: [PATCH] Add enum MDTwoFactorAuthType --- l18n | 2 +- src/enums/MDTwoFactorAuthType.php | 195 ++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 src/enums/MDTwoFactorAuthType.php diff --git a/l18n b/l18n index 82eac57..592501f 160000 --- a/l18n +++ b/l18n @@ -1 +1 @@ -Subproject commit 82eac5766eb1b6aa1c85b36cd02b52e029b7687c +Subproject commit 592501f34836a91108cc64ebc7074818d2f0c686 diff --git a/src/enums/MDTwoFactorAuthType.php b/src/enums/MDTwoFactorAuthType.php new file mode 100644 index 0000000..028019a --- /dev/null +++ b/src/enums/MDTwoFactorAuthType.php @@ -0,0 +1,195 @@ + self::none, + "1", + "email" => self::email, + "2", + "webauthn_2fa" => self::webauthn_2fa, + "3", + "webauthn_passwordless" => self::webauthn_passwordless, + "4", + "totp" => self::totp, + "5", + "visiting_scientist" => self::visiting_scientist, + "6", + "specifically_determined" => self::specifically_determined, + "7", + "frontend_only_user" => self::frontend_only_user, + default => throw new MDpageParameterNotFromListException("Unknown two factor authentication type"), + }; + + } + + /** + * Returns a value of this type based on an integer. + * + * @param integer $input Input to get a value from. + * + * @return MDTwoFactorAuthType + */ + public static function fromInt(int $input):MDTwoFactorAuthType { + + return match($input) { + 0 => self::none, + 1 => self::email, + 2 => self::webauthn_2fa, + 3 => self::webauthn_passwordless, + 4 => self::totp, + 5 => self::visiting_scientist, + 6 => self::specifically_determined, + 7 => self::frontend_only_user, + default => throw new MDpageParameterNotFromListException("Unknown two factor authentication type"), + }; + + } + + /** + * Lists all available names. + * + * @return array + */ + public static function caseNames():array { + + $output = []; + + $cases = self::cases(); + foreach ($cases as $case) { + $output[] = $case->name; + } + + return $output; + + } + + /** + * Gets an unsorted list of the entries in a translated version. + * + * @param MDTlLoader $tlLoader Translation loader. + * + * @return array + */ + public static function getUnsortedList(MDTlLoader $tlLoader):array { + + $output = []; + foreach (self::cases() as $case) { + $output[$case->toString()] = $tlLoader->tl("two_factor_auth_types", "two_factor_auth_types", $case->toString()); + } + + return $output; + + } + + /** + * Gets a sorted list of the entries in a translated version. + * + * @param MDTlLoader $tlLoader Translation loader. + * + * @return array + */ + public static function getSortedList(MDTlLoader $tlLoader):array { + + $output = self::getUnsortedList($tlLoader); + asort($output); + return $output; + + } + + /** + * Lists all available names. + * + * @return array + */ + public static function caseInts():array { + + $output = []; + + $cases = self::cases(); + foreach ($cases as $case) { + $output[] = $case->toInt(); + } + + return $output; + + } + + /** + * Returns integer representation of object record status. + * + * @return integer + */ + public function toInt():int { + + return match($this) { + self::none => 0, + self::email => 1, + self::webauthn_2fa => 2, + self::webauthn_passwordless => 3, + self::totp => 4, + }; + + } + + /** + * Returns canonical string representation of object record status. + * + * @return string + */ + public function toString():string { + + return match($this) { + self::none => "none", + self::email => "email", + self::webauthn_2fa => "webauthn_2fa", + self::webauthn_passwordless => "webauthn_passwordless", + self::totp => "totp", + }; + + } + + /** + * Returns the name of the current value in translation. + * + * @param MDTlLoader $tlLoader Translation loader. + * + * @return string + */ + public function getTledName(MDTlLoader $tlLoader):string { + + return $tlLoader->tl("two_factor_auth_types", "two_factor_auth_types", $this->toString()); + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->toString(); + + } +}