-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnum.php
50 lines (40 loc) · 973 Bytes
/
Enum.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace EXSyst\Common;
abstract class Enum
{
private function __construct()
{
}
public static function isValid($value)
{
return static::getName($value) !== null;
}
public static function getValue($name)
{
$values = static::getValues();
if (!isset($values[$name])) {
return;
}
return $values[$name];
}
public static function getName($value)
{
$name = array_search($value, static::getValues());
if ($name === false) {
return;
}
return $name;
}
public static function getValues($case_lower = false)
{
static $values = null;
if ($values === null) {
$clazz = new \ReflectionClass(get_called_class());
$values = $clazz->getConstants();
}
if ($case_lower) {
$values = array_change_key_case($values);
}
return $values;
}
}