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 | */ |
||
31 | 28 | public function __construct($value) |
|
43 | |||
44 | /** |
||
45 | * @return string |
||
46 | */ |
||
47 | 4 | public function __toString() |
|
51 | |||
52 | /** |
||
53 | * Get the serialized value. |
||
54 | * |
||
55 | * @return mixed |
||
56 | */ |
||
57 | 4 | public function jsonSerialize() |
|
61 | |||
62 | /** |
||
63 | * Get the enum key. |
||
64 | * |
||
65 | * @return mixed |
||
66 | */ |
||
67 | 4 | public function getKey() |
|
71 | |||
72 | /** |
||
73 | * Get the enum value. |
||
74 | * |
||
75 | * @return mixed |
||
76 | */ |
||
77 | 4 | public function getValue() |
|
81 | |||
82 | /** |
||
83 | * Get the enum keys. |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | 4 | public static function keys() |
|
93 | |||
94 | /** |
||
95 | * Get the enum values. |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | 4 | public static function values() |
|
107 | |||
108 | /** |
||
109 | * Get the enum constants. |
||
110 | * |
||
111 | * @return \Illuminate\Support\Collection |
||
112 | */ |
||
113 | 40 | public static function constants() |
|
123 | |||
124 | /** |
||
125 | * Returns a new enum instance when called statically. |
||
126 | * |
||
127 | * @param string $name |
||
128 | * @param array $arguments |
||
129 | * |
||
130 | * @return static |
||
131 | */ |
||
132 | 8 | public static function __callStatic($name, array $arguments) |
|
144 | } |
||
145 |