Add enum MDTransportMethod

This commit is contained in:
Joshua Ramon Enslin 2023-01-31 18:43:02 +01:00
parent 63895258ad
commit 99cf6bf552
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 113 additions and 1 deletions

2
l18n

@ -1 +1 @@
Subproject commit 388b7f3db08f8f2c4a40fdc3d8f29c7f608b748b
Subproject commit 03b5464bb8186087d22573abbdbea5aab5260dcc

View File

@ -0,0 +1,112 @@
<?PHP
/**
* Represents a method of transportation for objects.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a method of transportation for objects.
*/
enum MDTransportMethod implements MDValueEnumInterface, JsonSerializable {
case unknown;
case car;
case ship;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDTransportMethod
*/
public static function fromString(string $input):MDTransportMethod {
return match($input) {
'unknown' => self::unknown,
'car' => self::car,
'ship' => self::ship,
default => throw new MDpageParameterNotFromListException("Unknown shipment status"),
};
}
/**
* Returns the default status.
*
* @return MDTransportMethod
*/
public static function getDefault():MDTransportMethod {
return self::unknown;
}
/**
* 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 {
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "shipment_method_set", "shipment_method_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(), "shipment_method_set", "shipment_method_set");
}
/**
* 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("shipment_method_set", "shipment_method_set", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}