1 | <?php |
||
16 | abstract class FlaggedEnum extends ReadableEnum |
||
17 | { |
||
18 | const NONE = 0; |
||
19 | |||
20 | /** @var array */ |
||
21 | private static $masks = []; |
||
22 | |||
23 | /** @var array */ |
||
24 | private static $readables = []; |
||
25 | |||
26 | /** @var int[] */ |
||
27 | protected $flags; |
||
28 | |||
29 | 30 | /** |
|
30 | * {@inheritdoc} |
||
31 | 30 | */ |
|
32 | 1 | public static function accepts($value): bool |
|
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | 8 | */ |
|
48 | public static function readables(): array |
||
62 | 2 | ||
63 | /** |
||
64 | 2 | * {@inheritdoc} |
|
65 | 2 | * |
|
66 | 2 | * @param string $separator A delimiter used between each bit flag's readable string |
|
67 | */ |
||
68 | public static function readableFor($value, string $separator = '; '): string |
||
93 | |||
94 | 26 | /** |
|
95 | 1 | * Gets the human representation for the none value. |
|
96 | 1 | * |
|
97 | 1 | * @return string |
|
98 | 1 | */ |
|
99 | 1 | protected static function readableForNone(): string |
|
103 | |||
104 | 1 | /** |
|
105 | * Gets an integer value of the possible flags for enumeration. |
||
106 | * |
||
107 | * @throws LogicException If the possibles values are not valid bit flags |
||
108 | * |
||
109 | 25 | * @return int |
|
110 | */ |
||
111 | private static function getBitmask(): int |
||
132 | 7 | ||
133 | 7 | /** |
|
134 | * {@inheritdoc} |
||
135 | * |
||
136 | * @param string $separator A delimiter used between each bit flag's readable string |
||
137 | */ |
||
138 | 13 | public function getReadable(string $separator = '; '): string |
|
142 | |||
143 | /** |
||
144 | * Gets an array of bit flags of the value. |
||
145 | * |
||
146 | * @return array |
||
147 | */ |
||
148 | 9 | public function getFlags(): array |
|
161 | |||
162 | /** |
||
163 | * Determines whether the specified flag is set in a numeric value. |
||
164 | * |
||
165 | * @param int $bitFlag The bit flag or bit flags |
||
166 | 2 | * |
|
167 | * @return bool True if the bit flag or bit flags are also set in the current instance; otherwise, false |
||
168 | 2 | */ |
|
169 | 1 | public function hasFlag(int $bitFlag): bool |
|
177 | |||
178 | /** |
||
179 | * Computes a new value with given flags, and returns the corresponding instance. |
||
180 | * |
||
181 | * @param int $flags The bit flag or bit flags |
||
182 | * |
||
183 | * @throws InvalidValueException When $flags is not acceptable for this enumeration type |
||
184 | 4 | * |
|
185 | * @return static The enum instance for computed value |
||
186 | 4 | */ |
|
187 | 1 | public function withFlags(int $flags): self |
|
195 | |||
196 | /** |
||
197 | * Computes a new value without given flags, and returns the corresponding instance. |
||
198 | * |
||
199 | * @param int $flags The bit flag or bit flags |
||
200 | * |
||
201 | * @throws InvalidValueException When $flags is not acceptable for this enumeration type |
||
202 | * |
||
203 | * @return static The enum instance for computed value |
||
204 | */ |
||
205 | public function withoutFlags(int $flags): self |
||
213 | } |
||
214 |