From 9cd45355cfb0ffdc8c1aaf12a447616796ab8434 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 15 Sep 2016 21:01:03 +0200 Subject: [PATCH] Add get name by value --- Datatypes/Enum.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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. *