Add enum MDTransportMethod
This commit is contained in:
parent
63895258ad
commit
99cf6bf552
2
l18n
2
l18n
|
@ -1 +1 @@
|
|||
Subproject commit 388b7f3db08f8f2c4a40fdc3d8f29c7f608b748b
|
||||
Subproject commit 03b5464bb8186087d22573abbdbea5aab5260dcc
|
112
src/enums/MDTransportMethod.php
Normal file
112
src/enums/MDTransportMethod.php
Normal 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;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user