From 99cf6bf552a5ad9fd19d44e06ca95108d8b6a69c Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 31 Jan 2023 18:43:02 +0100 Subject: [PATCH] Add enum MDTransportMethod --- l18n | 2 +- src/enums/MDTransportMethod.php | 112 ++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/enums/MDTransportMethod.php diff --git a/l18n b/l18n index 388b7f3..03b5464 160000 --- a/l18n +++ b/l18n @@ -1 +1 @@ -Subproject commit 388b7f3db08f8f2c4a40fdc3d8f29c7f608b748b +Subproject commit 03b5464bb8186087d22573abbdbea5aab5260dcc diff --git a/src/enums/MDTransportMethod.php b/src/enums/MDTransportMethod.php new file mode 100644 index 0000000..e39486e --- /dev/null +++ b/src/enums/MDTransportMethod.php @@ -0,0 +1,112 @@ + + */ +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 + */ + 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 { + 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 + */ + 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; + + } +}