Add enum representation of currencies (MDCurrency)
This commit is contained in:
+1
-1
Submodule l18n updated: 4d9221ef5c...407bdc5f21
@@ -22,11 +22,11 @@ final class MDCurrenciesSet extends MDValueSet {
|
||||
'es-Real',
|
||||
'eu-EUR',
|
||||
'fr-FF',
|
||||
'id-IDR',
|
||||
'hu-Ft',
|
||||
'hu-Lari',
|
||||
'hu-Pengő',
|
||||
'hu-Korona',
|
||||
'id-IDR',
|
||||
'nl-Gulden',
|
||||
'pl-Złoty',
|
||||
'ru-RUB',
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
<?PHP
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a currency.
|
||||
*/
|
||||
enum MDCurrency implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case none;
|
||||
case byBYN;
|
||||
case chCHF;
|
||||
case ddrMark;
|
||||
case ddrMDN;
|
||||
case deDM;
|
||||
case deRM;
|
||||
case esReal;
|
||||
case euEUR;
|
||||
case frFF;
|
||||
case huFt;
|
||||
case huLari;
|
||||
case huPengo;
|
||||
case huKorona;
|
||||
case idIDR;
|
||||
case nlGulden;
|
||||
case plZloty;
|
||||
case ruRUB;
|
||||
case suSUR;
|
||||
case uaUAH;
|
||||
case uaUAK;
|
||||
case ukGBP;
|
||||
case usUSD;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDCurrency
|
||||
*/
|
||||
public static function fromString(string $input):MDCurrency {
|
||||
|
||||
return match($input) {
|
||||
"0",
|
||||
"",
|
||||
"none" => self::none,
|
||||
"1",
|
||||
"by-BYN" => self::byBYN,
|
||||
"2",
|
||||
"ch-CHF" => self::chCHF,
|
||||
"3",
|
||||
"ddr-Mark" => self::ddrMark,
|
||||
"4",
|
||||
"ddr-MDN" => self::ddrMDN,
|
||||
"5",
|
||||
"de-DM" => self::deDM,
|
||||
"6",
|
||||
"de-RM" => self::deRM,
|
||||
"7",
|
||||
"es-Real" => self::esReal,
|
||||
"8",
|
||||
"eu-EUR" => self::euEUR,
|
||||
"9",
|
||||
"fr-FF" => self::frFF,
|
||||
"10",
|
||||
"hu-Ft" => self::huFt,
|
||||
"11",
|
||||
"hu-Lari" => self::huLari,
|
||||
"12",
|
||||
"hu-Pengő" => self::huPengo,
|
||||
"13",
|
||||
"hu-Korona" => self::huKorona,
|
||||
"14",
|
||||
"id-IDR" => self::idIDR,
|
||||
"15",
|
||||
"nl-Gulden" => self::nlGulden,
|
||||
"16",
|
||||
"pl-Złoty" => self::plZloty,
|
||||
"17",
|
||||
"ru-RUB" => self::ruRUB,
|
||||
"18",
|
||||
"su-SUR" => self::suSUR,
|
||||
"19",
|
||||
"ua-UAH" => self::uaUAH,
|
||||
"20",
|
||||
"ua-UAK" => self::uaUAK,
|
||||
"21",
|
||||
"uk-GBP" => self::ukGBP,
|
||||
"22",
|
||||
"ua-USD" => self::usUSD,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown currency"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDCurrency
|
||||
*/
|
||||
public static function fromInt(int $input):MDCurrency {
|
||||
|
||||
return match($input) {
|
||||
0 => self::none,
|
||||
1 => self::byBYN,
|
||||
2 => self::chCHF,
|
||||
3 => self::ddrMark,
|
||||
4 => self::ddrMDN,
|
||||
5 => self::deDM,
|
||||
6 => self::deRM,
|
||||
7 => self::esReal,
|
||||
8 => self::euEUR,
|
||||
9 => self::frFF,
|
||||
10 => self::huFt,
|
||||
11 => self::huLari,
|
||||
12 => self::huPengo,
|
||||
13 => self::huKorona,
|
||||
14 => self::idIDR,
|
||||
15 => self::nlGulden,
|
||||
16 => self::plZloty,
|
||||
17 => self::ruRUB,
|
||||
18 => self::suSUR,
|
||||
19 => self::uaUAH,
|
||||
20 => self::uaUAK,
|
||||
21 => self::ukGBP,
|
||||
22 => self::usUSD,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown currency"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all available names.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function caseNames():array {
|
||||
|
||||
$output = [];
|
||||
|
||||
$cases = self::cases();
|
||||
foreach ($cases as $case) {
|
||||
$output[] = $case->toString();
|
||||
}
|
||||
|
||||
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 {
|
||||
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "currencies_set", "currencies_set");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
return MDValueSet::getTlSortedList($tlLoader, self::caseNames(), "currencies_set", "currencies_set");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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::byBYN => 1,
|
||||
self::chCHF => 2,
|
||||
self::ddrMark => 3,
|
||||
self::ddrMDN => 4,
|
||||
self::deDM => 5,
|
||||
self::deRM => 6,
|
||||
self::esReal => 7,
|
||||
self::euEUR => 8,
|
||||
self::frFF => 9,
|
||||
self::huFt => 10,
|
||||
self::huLari => 11,
|
||||
self::huPengo => 12,
|
||||
self::huKorona => 13,
|
||||
self::idIDR => 14,
|
||||
self::nlGulden => 15,
|
||||
self::plZloty => 16,
|
||||
self::ruRUB => 17,
|
||||
self::suSUR => 18,
|
||||
self::uaUAH => 19,
|
||||
self::uaUAK => 20,
|
||||
self::ukGBP => 21,
|
||||
self::usUSD => 22,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string representation.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString():string {
|
||||
|
||||
return match($this) {
|
||||
self::none => '',
|
||||
self::byBYN => 'by-BYN',
|
||||
self::chCHF => 'ch-CHF',
|
||||
self::ddrMark => 'ddr-Mark',
|
||||
self::ddrMDN => "ddr-MDN",
|
||||
self::deDM => "de-DM",
|
||||
self::deRM => "de-RM",
|
||||
self::esReal => "es-Real",
|
||||
self::euEUR => "eu-EUR",
|
||||
self::frFF => "fr-FF",
|
||||
self::huFt => "hu-Ft",
|
||||
self::huLari => "hu-Lari",
|
||||
self::huPengo => "hu-Pengő",
|
||||
self::huKorona => "hu-Korona",
|
||||
self::idIDR => "id-IDR",
|
||||
self::nlGulden => "nl-Gulden",
|
||||
self::plZloty => "pl-Złoty",
|
||||
self::ruRUB => "ru-RUB",
|
||||
self::suSUR => "su-SUR",
|
||||
self::uaUAH => "ua-UAH",
|
||||
self::uaUAK => "ua-UAK",
|
||||
self::ukGBP => "uk-GBP",
|
||||
self::usUSD => "ua-USD",
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the current value in translation.
|
||||
*
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTledName(MDTlLoader $tlLoader):string {
|
||||
|
||||
if ($this === self::none) return '';
|
||||
return $tlLoader->tl("currencies_set", "currencies_set", $this->toString());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->toString();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
<?PHP
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a day of week.
|
||||
*/
|
||||
enum MDDayOfWeek implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case monday;
|
||||
case tuesday;
|
||||
case wednesday;
|
||||
case thursday;
|
||||
case friday;
|
||||
case saturday;
|
||||
case sunday;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDDayOfWeek
|
||||
*/
|
||||
public static function fromString(string $input):MDDayOfWeek {
|
||||
|
||||
return match($input) {
|
||||
"0",
|
||||
"monday" => self::monday,
|
||||
"1",
|
||||
"tuesday" => self::tuesday,
|
||||
"2",
|
||||
"wednesday" => self::wednesday,
|
||||
"3",
|
||||
"thursday" => self::thursday,
|
||||
"4",
|
||||
"friday" => self::friday,
|
||||
"5",
|
||||
"saturday" => self::saturday,
|
||||
"6",
|
||||
"sunday" => self::sunday,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown day of week"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDDayOfWeek
|
||||
*/
|
||||
public static function fromInt(int $input):MDDayOfWeek {
|
||||
|
||||
return match($input) {
|
||||
0 => self::monday,
|
||||
1 => self::tuesday,
|
||||
2 => self::wednesday,
|
||||
3 => self::thursday,
|
||||
4 => self::friday,
|
||||
5 => self::saturday,
|
||||
6 => self::sunday,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown day of week"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all available names.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function caseNames():array {
|
||||
|
||||
$output = [];
|
||||
|
||||
$cases = self::cases();
|
||||
foreach ($cases as $case) {
|
||||
$output[] = $case->toString();
|
||||
}
|
||||
|
||||
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 {
|
||||
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "day_of_week", "day_of_week");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
return MDValueSet::getTlSortedList($tlLoader, self::caseNames(), "day_of_week", "day_of_week");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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::monday => 0,
|
||||
self::tuesday => 1,
|
||||
self::wednesday => 2,
|
||||
self::thursday => 3,
|
||||
self::friday => 4,
|
||||
self::saturday => 5,
|
||||
self::sunday => 6,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string representation.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the current value in translation.
|
||||
*
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTledName(MDTlLoader $tlLoader):string {
|
||||
|
||||
if ($this === self::monday) return '';
|
||||
return $tlLoader->tl("day_of_week", "day_of_week", $this->name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?PHP
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents an icon available to be selected for ticket types.
|
||||
*/
|
||||
enum MDInstitutionTicketTypeIcon implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case person;
|
||||
case child;
|
||||
case calendar;
|
||||
case disabled;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDInstitutionTicketTypeIcon
|
||||
*/
|
||||
public static function fromString(string $input):MDInstitutionTicketTypeIcon {
|
||||
|
||||
return match($input) {
|
||||
"0",
|
||||
"person" => self::person,
|
||||
"1",
|
||||
"child" => self::child,
|
||||
"2",
|
||||
"calendar" => self::calendar,
|
||||
"3",
|
||||
"disabled" => self::disabled,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown ticket type icon"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDInstitutionTicketTypeIcon
|
||||
*/
|
||||
public static function fromInt(int $input):MDInstitutionTicketTypeIcon {
|
||||
|
||||
return match($input) {
|
||||
0 => self::person,
|
||||
1 => self::child,
|
||||
2 => self::calendar,
|
||||
3 => self::disabled,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown ticket type icon"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all available names.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function caseNames():array {
|
||||
|
||||
$output = [];
|
||||
|
||||
$cases = self::cases();
|
||||
foreach ($cases as $case) {
|
||||
$output[] = $case->toString();
|
||||
}
|
||||
|
||||
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 {
|
||||
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "ticket_type_icon", "ticket_type_icon");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
return MDValueSet::getTlSortedList($tlLoader, self::caseNames(), "ticket_type_icon", "ticket_type_icon");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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::person => 0,
|
||||
self::child => 1,
|
||||
self::calendar => 2,
|
||||
self::disabled => 3,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string representation.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString():string {
|
||||
|
||||
return match($this) {
|
||||
self::person => 'person',
|
||||
self::child => 'child',
|
||||
self::calendar => 'calendar',
|
||||
self::disabled => 'disabled',
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the current value in translation.
|
||||
*
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTledName(MDTlLoader $tlLoader):string {
|
||||
|
||||
if ($this === self::person) return '';
|
||||
return $tlLoader->tl("ticket_type_icon", "ticket_type_icon", $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