1 | <?php |
||
10 | abstract class Enum |
||
11 | { |
||
12 | /** @var string */ |
||
13 | private $value; |
||
14 | |||
15 | /** @var array */ |
||
16 | private static $loaded = []; |
||
17 | |||
18 | /** @var array */ |
||
19 | protected static $values = []; |
||
20 | |||
21 | abstract public function langKey(): string; |
||
22 | |||
23 | /** |
||
24 | * @param string $value |
||
25 | */ |
||
26 | 10 | public function __construct($value) |
|
31 | |||
32 | /** |
||
33 | * Return the enumerators values. |
||
34 | * |
||
35 | * @param bool $keys |
||
36 | * @return array |
||
37 | */ |
||
38 | 28 | public static function allValues($keys = false): array |
|
48 | |||
49 | /** |
||
50 | * Return a collection of the declared values. |
||
51 | * |
||
52 | * @param bool $keys |
||
53 | * @return Illuminate\Support\Collection |
||
54 | */ |
||
55 | 7 | public static function collect($keys = false): Collection |
|
59 | |||
60 | /** |
||
61 | * Return an instance of a desired value. |
||
62 | * |
||
63 | * @param string $value |
||
64 | * @return DavidIanBonner\Enumerated\Enum |
||
65 | */ |
||
66 | 13 | public static function ofType($value): self |
|
80 | |||
81 | /** |
||
82 | * Return the value. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | 10 | public function value(): string |
|
90 | |||
91 | /** |
||
92 | * Validate the value. |
||
93 | * |
||
94 | * @param mixed $value |
||
95 | * @throws DavidIanBonner\Enumerated\EnumNotValidException |
||
96 | * @return void |
||
97 | */ |
||
98 | 16 | public static function validateValue($value) |
|
104 | |||
105 | /** |
||
106 | * Check the value is valid and return a bool. |
||
107 | * |
||
108 | * @param mixed $value |
||
109 | * @return bool |
||
110 | */ |
||
111 | 3 | public static function isValid($value): bool |
|
121 | |||
122 | /** |
||
123 | * Get the declared constants. |
||
124 | * |
||
125 | * @return array |
||
126 | */ |
||
127 | 8 | protected static function getDeclaredConstants(): array |
|
133 | |||
134 | /** |
||
135 | * @return array |
||
136 | */ |
||
137 | 4 | public static function toSelect(): array |
|
147 | |||
148 | /** |
||
149 | * @return string |
||
150 | */ |
||
151 | 7 | public function line(): string |
|
161 | |||
162 | 5 | public function langKeyPrefix(): string |
|
166 | } |
||
167 |