mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-17 20:38:41 +00:00
Add get name by value
This commit is contained in:
parent
2347f3fb29
commit
9cd45355cf
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user