Add enum MDTwoFactorAuthType
This commit is contained in:
+1
-1
Submodule l18n updated: 82eac5766e...592501f348
@@ -0,0 +1,195 @@
|
||||
<?PHP
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a way a user authenticates.
|
||||
*/
|
||||
enum MDTwoFactorAuthType implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case none;
|
||||
case email;
|
||||
case webauthn_2fa;
|
||||
case webauthn_passwordless;
|
||||
case totp;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDTwoFactorAuthType
|
||||
*/
|
||||
public static function fromString(string $input):MDTwoFactorAuthType {
|
||||
|
||||
return match($input) {
|
||||
"0",
|
||||
"none" => 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<string>
|
||||
*/
|
||||
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<string, string>
|
||||
*/
|
||||
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<string, string>
|
||||
*/
|
||||
public static function getSortedList(MDTlLoader $tlLoader):array {
|
||||
|
||||
$output = self::getUnsortedList($tlLoader);
|
||||
asort($output);
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all available names.
|
||||
*
|
||||
* @return array<integer>
|
||||
*/
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user