diff --git a/src/Helpers/EnumHelper.php b/src/Helpers/EnumHelper.php new file mode 100644 index 0000000..cf2f5de --- /dev/null +++ b/src/Helpers/EnumHelper.php @@ -0,0 +1,37 @@ +'friendly name'. Initially intended for use in a Nette forms. + * Without overriding the method returns the 'friendly name' the same as the 'enum value' or + * in case of non-backed enum it returns a pair of 'enum keys'. + */ + public static function getFriendlyList(): array + { + $values = self::values(); + + $isNonBackedEnum = count($values) === 0; + if ($isNonBackedEnum) { + $names = self::names(); + return array_combine($names, $names); + } + + return array_combine($values, $values); + } +}