Add get name by value

This commit is contained in:
Dennis Eichhorn 2016-09-15 21:01:03 +02:00
parent 2347f3fb29
commit 9cd45355cf

View File

@ -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 <d.eichhorn@oms.com>
*/
public static function getName(string $value)
{
$arr = self::getConstants();
return array_search($value, $arr);
}
/**
* Checking enum name.
*