Skip to content

Commit 644c4cb

Browse files
committed
Add two new methods, valueDesc and getDesc
1 parent 3ed5f01 commit 644c4cb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Enum.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,29 @@ public static function search($value)
278278
return \array_search($value, static::toArray(), true);
279279
}
280280

281+
/**
282+
* Constant value desc array
283+
* @return array
284+
*/
285+
public static function valueDesc()
286+
{
287+
return [];
288+
}
289+
290+
/**
291+
* Get constant value desc
292+
* @param $value
293+
* @return mixed
294+
*/
295+
public static function getDesc($value)
296+
{
297+
if (!isset(static::valueDesc()[$value])) {
298+
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . static::class);
299+
}
300+
301+
return static::valueDesc()[$value];
302+
}
303+
281304
/**
282305
* Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a class constant
283306
*

0 commit comments

Comments
 (0)