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 | /** |
||
22 | * @param string $value |
||
23 | */ |
||
24 | 8 | public function __construct($value) |
|
29 | |||
30 | /** |
||
31 | * Return the enumerators values. |
||
32 | * |
||
33 | * @param bool $keys |
||
34 | * @return array |
||
35 | */ |
||
36 | 26 | public static function allValues($keys = false): array |
|
46 | |||
47 | /** |
||
48 | * Return a collection of the declared values. |
||
49 | * |
||
50 | * @param bool $keys |
||
51 | * @return Illuminate\Support\Collection |
||
52 | */ |
||
53 | 5 | public static function collect($keys = false): Collection |
|
57 | |||
58 | /** |
||
59 | * Return an instance of a desired value. |
||
60 | * |
||
61 | * @param string $value |
||
62 | * @return DavidIanBonner\Enumerated\Enum |
||
63 | */ |
||
64 | 11 | public static function ofType($value): self |
|
78 | |||
79 | /** |
||
80 | * Return the value. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 8 | public function value(): string |
|
88 | |||
89 | /** |
||
90 | * Validate the value. |
||
91 | * |
||
92 | * @param mixed $value |
||
93 | * @throws DavidIanBonner\Enumerated\EnumNotValidException |
||
94 | * @return void |
||
95 | */ |
||
96 | 14 | public static function validateValue($value) |
|
102 | |||
103 | /** |
||
104 | * Check the value is valid and return a bool. |
||
105 | * |
||
106 | * @param mixed $value |
||
107 | * @return bool |
||
108 | */ |
||
109 | 3 | public static function isValid($value): bool |
|
119 | |||
120 | /** |
||
121 | * Get the declared constants. |
||
122 | * |
||
123 | * @return array |
||
124 | */ |
||
125 | 6 | protected static function getDeclaredConstants(): array |
|
131 | |||
132 | /** |
||
133 | * @return array |
||
134 | */ |
||
135 | 2 | public static function toSelect(): array |
|
145 | |||
146 | /** |
||
147 | * @return string |
||
148 | */ |
||
149 | 5 | public function line(): string |
|
155 | |||
156 | public abstract function langKey(): string; |
||
157 | } |
||
158 |