diff --git a/Datatypes/Enum.php b/Datatypes/Enum.php index 40972b527..5f7a0a8d1 100644 --- a/Datatypes/Enum.php +++ b/Datatypes/Enum.php @@ -102,6 +102,25 @@ abstract class Enum return constant('static::' . $name); } + /** + * Get enum name by value. + * + * @param string $value Enum value + * + * @return mixed + * + * @throws \Exception Throws this exception if the constant is not defined in the enum class. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function getName(string $value) + { + $arr = self::getConstants(); + + return array_search($value, $arr); + } + /** * Checking enum name. *