From 06a39eb1471a51d75428a193087bd9814c4d2413 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sun, 9 Apr 2023 01:37:39 +0200 Subject: [PATCH] Add enum for categorizing external repos --- l18n | 2 +- .../MDInstitutionExternalIdRepository.php | 132 ++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 src/enums/MDInstitutionExternalIdRepository.php diff --git a/l18n b/l18n index 8d83978..808895c 160000 --- a/l18n +++ b/l18n @@ -1 +1 @@ -Subproject commit 8d83978b4f1159445f16ed9bb15b791ea9a4724a +Subproject commit 808895ce187b34de591bbf7f4c1d9039a480e615 diff --git a/src/enums/MDInstitutionExternalIdRepository.php b/src/enums/MDInstitutionExternalIdRepository.php new file mode 100644 index 0000000..c00b442 --- /dev/null +++ b/src/enums/MDInstitutionExternalIdRepository.php @@ -0,0 +1,132 @@ + + */ +declare(strict_types = 1); + +/** + * Represents a possible status for to-dos. + */ +enum MDInstitutionExternalIdRepository implements MDValueEnumInterface, JsonSerializable { + + case hu_ksh; // https://en.wikipedia.org/wiki/Hungarian_Central_Statistical_Office + + const VALIDATION_PATTERN_HTML = [ + 'hu_ksh' => '[0-9]{8}-[0-9]{4}-[0-9]{3}-[0-9]{2}', + ]; + + const VALIDATION_PATTERN_PHP = [ + 'hu_ksh' => '[0-9]{8}-[0-9]{4}-[0-9]{3}-[0-9]{2}', + ]; + + /** + * Returns a value of this type based on a string. + * + * @param string $input Input to get a value from. + * + * @return MDInstitutionExternalIdRepository + */ + public static function fromString(string $input):MDInstitutionExternalIdRepository { + + return match($input) { + 'hu_ksh' => self::hu_ksh, + default => throw new MDpageParameterNotFromListException("Unknown external repository"), + }; + + } + + /** + * 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(), "institution_external_id_repositories", "institution_external_id_repositories"); + + } + + /** + * 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(), "institution_external_id_repositories", "institution_external_id_repositories"); + + } + + /** + * 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("institution_external_id_repositories", "institution_external_id_repositories", $this->name); + + } + + /** + * Returns the HTML pattern. + * + * @param MDTlLoader $tlLoader Translation loader. + * + * @return string + */ + public function getValidationPatternHtml():string { + + return self::VALIDATION_PATTERN_HTML[$this->name]; + + } + + /** + * Returns the PHP pattern. + * + * @param MDTlLoader $tlLoader Translation loader. + * + * @return string + */ + public function getValidationPatternPhp():string { + + return self::VALIDATION_PATTERN_PHP[$this->name]; + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->name; + + } +}