1 | <?php |
||
10 | abstract class Enum implements JsonSerializable |
||
11 | { |
||
12 | /** |
||
13 | * The enum value. |
||
14 | * |
||
15 | * @var mixed |
||
16 | */ |
||
17 | protected $value; |
||
18 | |||
19 | /** |
||
20 | * The enum constants. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected static $constants = []; |
||
25 | |||
26 | /** |
||
27 | * Create a new enum instance. |
||
28 | * |
||
29 | * @param mixed $value |
||
30 | 12 | */ |
|
31 | public function __construct($value) |
||
43 | |||
44 | /** |
||
45 | * @return string |
||
46 | 2 | */ |
|
47 | public function __toString() |
||
51 | |||
52 | /** |
||
53 | * Serialize enum value |
||
54 | * |
||
55 | * @return mixed |
||
56 | 2 | */ |
|
57 | public function jsonSerialize() |
||
61 | |||
62 | /** |
||
63 | * Get the enum key. |
||
64 | * |
||
65 | * @return mixed |
||
66 | 2 | */ |
|
67 | public function getKey() |
||
71 | |||
72 | /** |
||
73 | * Get the enum value. |
||
74 | * |
||
75 | * @return mixed |
||
76 | 2 | */ |
|
77 | public function getValue() |
||
81 | |||
82 | /** |
||
83 | * Get the enum keys. |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | public static function keys() |
||
93 | 2 | ||
94 | 2 | /** |
|
95 | * Get the enum values. |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | public static function values() |
||
107 | |||
108 | /** |
||
109 | * Get the enum constants. |
||
110 | 18 | * |
|
111 | * @return \Illuminate\Support\Collection |
||
112 | */ |
||
113 | public static function constants() |
||
123 | 4 | ||
124 | 2 | /** |
|
125 | * Returns a new enum instance when called statically. |
||
126 | * |
||
127 | 2 | * @param string $name |
|
128 | 2 | * @param array $arguments |
|
129 | 2 | * |
|
130 | 2 | * @return static |
|
131 | */ |
||
132 | public static function __callStatic($name, array $arguments) |
||
144 | } |
||
145 |