1 | <?php |
||
16 | abstract class FlaggedEnum extends ReadableEnum |
||
17 | { |
||
18 | const NONE = 0; |
||
19 | |||
20 | /** @var array */ |
||
21 | private static $masks = []; |
||
22 | |||
23 | /** @var int[] */ |
||
24 | protected $flags; |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 30 | public static function accepts($value): bool |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public static function readables(): array |
||
56 | 7 | ||
57 | /** |
||
58 | 7 | * {@inheritdoc} |
|
59 | 5 | * |
|
60 | * @param string $separator A delimiter used between each bit flag's readable string |
||
61 | */ |
||
62 | 2 | public static function readableFor($value, string $separator = '; '): string |
|
87 | |||
88 | /** |
||
89 | * Gets the human representation for the none value. |
||
90 | 26 | * |
|
91 | * @return string |
||
92 | 26 | */ |
|
93 | protected static function readableForNone(): string |
||
97 | 1 | ||
98 | 1 | /** |
|
99 | 1 | * Gets an integer value of the possible flags for enumeration. |
|
100 | * |
||
101 | 1 | * @throws LogicException If the possibles values are not valid bit flags |
|
102 | * |
||
103 | * @return int |
||
104 | 1 | */ |
|
105 | private static function getBitmask(): int |
||
126 | |||
127 | 13 | /** |
|
128 | * {@inheritdoc} |
||
129 | 13 | * |
|
130 | 7 | * @param string $separator A delimiter used between each bit flag's readable string |
|
131 | 7 | */ |
|
132 | 7 | public function getReadable(string $separator = '; '): string |
|
136 | |||
137 | /** |
||
138 | 13 | * Gets an array of bit flags of the value. |
|
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | public function getFlags(): array |
||
155 | |||
156 | /** |
||
157 | * Determines whether the specified flag is set in a numeric value. |
||
158 | * |
||
159 | * @param int $bitFlag The bit flag or bit flags |
||
160 | * |
||
161 | * @return bool True if the bit flag or bit flags are also set in the current instance; otherwise, false |
||
162 | */ |
||
163 | public function hasFlag(int $bitFlag): bool |
||
171 | |||
172 | 1 | /** |
|
173 | * Computes a new value with given flags, and returns the corresponding instance. |
||
174 | * |
||
175 | * @param int $flags The bit flag or bit flags |
||
176 | * |
||
177 | * @throws InvalidValueException When $flags is not acceptable for this enumeration type |
||
178 | * |
||
179 | * @return static The enum instance for computed value |
||
180 | */ |
||
181 | public function withFlags(int $flags): self |
||
189 | |||
190 | 3 | /** |
|
191 | * Computes a new value without given flags, and returns the corresponding instance. |
||
192 | * |
||
193 | * @param int $flags The bit flag or bit flags |
||
194 | * |
||
195 | * @throws InvalidValueException When $flags is not acceptable for this enumeration type |
||
196 | * |
||
197 | * @return static The enum instance for computed value |
||
198 | */ |
||
199 | public function withoutFlags(int $flags): self |
||
207 | } |
||
208 |