You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-5Lines changed: 24 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,25 +34,44 @@ $bitmask->set(EXECUTE);
34
34
```
35
35
36
36
Exists [EnumBitMask](/src/EnumBitMask.php), which allows the same using PHP enum:
37
+
The `EnumBitMask` allows you to work with bitmasks using PHP enums. It automatically detects if an enum is `int`-backed and uses the case's value. For `int`-backed enums, each case **must represent a single bit value** (e.g., 1, 2, 4, 8, etc.). Otherwise, an `InvalidEnumException` will be thrown.
37
38
38
39
```php
39
40
use BitMask\EnumBitMask;
40
41
41
42
enum Permissions
42
43
{
43
-
case READ;
44
-
case WRITE;
45
-
case EXECUTE;
44
+
case READ; // Mapped to 1
45
+
case WRITE; // Mapped to 2
46
+
case EXECUTE; // Mapped to 4
46
47
}
47
48
48
-
// two arguments: required enum class-string and integer mask (default: 0)
49
+
// Automatically maps UnitEnum based on their position
49
50
$bitmask = new EnumBitMask(Permissions::class, 0b111);
0 commit comments