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 | 6 | /** |
|
24 | * @param string $value |
||
25 | 6 | */ |
|
26 | 3 | public function __construct($value) |
|
31 | |||
32 | /** |
||
33 | * Return the enumerators values. |
||
34 | * |
||
35 | 24 | * @param bool $keys |
|
36 | * @return array |
||
37 | 24 | */ |
|
38 | public static function allValues($keys = false): array |
||
48 | |||
49 | /** |
||
50 | * Return a collection of the declared values. |
||
51 | * |
||
52 | 3 | * @param bool $keys |
|
53 | * @return Illuminate\Support\Collection |
||
54 | 3 | */ |
|
55 | public static function collect($keys = false): Collection |
||
59 | |||
60 | /** |
||
61 | * Return an instance of a desired value. |
||
62 | * |
||
63 | 6 | * @param string $value |
|
64 | * @return DavidIanBonner\Enumerated\Enum |
||
65 | 6 | */ |
|
66 | public static function ofType($value): self |
||
80 | |||
81 | /** |
||
82 | * Return the value. |
||
83 | 3 | * |
|
84 | * @return string |
||
85 | 3 | */ |
|
86 | public function value(): string |
||
90 | |||
91 | /** |
||
92 | * Validate the value. |
||
93 | * |
||
94 | * @param mixed $value |
||
95 | 12 | * @throws DavidIanBonner\Enumerated\EnumNotValidException |
|
96 | * @return void |
||
97 | 12 | */ |
|
98 | 6 | public static function validateValue($value) |
|
104 | |||
105 | /** |
||
106 | * Check the value is valid and return a bool. |
||
107 | * |
||
108 | 3 | * @param mixed $value |
|
109 | * @return bool |
||
110 | */ |
||
111 | 3 | public static function isValid($value): bool |
|
121 | |||
122 | /** |
||
123 | * Get the declared constants. |
||
124 | 6 | * |
|
125 | * @return array |
||
126 | 6 | */ |
|
127 | protected static function getDeclaredConstants(): array |
||
133 | |||
134 | /** |
||
135 | * @return array |
||
136 | */ |
||
137 | public static function toSelect(): array |
||
147 | |||
148 | /** |
||
149 | * @return string |
||
150 | */ |
||
151 | public function line(): string |
||
161 | |||
162 | public function langKeyPrefix(): string |
||
166 | } |
||
167 |