Based on Aliance/Bitmask, but without max bits' limitation.
Install the latest version with composer:
composer require aliance/infinite-bitmaskIf you checkout this library for testing purposes, install its dependencies:
docker run --rm -it --volume $PWD:/app -u $(id -u):$(id -g) composer:2 iuse Aliance\InfiniteBitmask\InfiniteBitmask;
$mask = new InfiniteBitmask();
$mask->setBit(2)->setBit(64);
var_dump($mask->issetBit(64)); // bool(true)
var_dump($mask->getMaskSlices()); // [0 => 4, 1 => 1]The permission example uses an integer-backed enum for bit positions.
A user already has Create permission. Granting Read sets another bit in slice 0.
Granting ViewAuditLog (bit 128) creates slice 2. When saving the array returned by
getMaskSlices(), keep its numeric keys so the constructor can restore the permissions.
Each key is a slice index and each value is a signed 64-bit mask. Bit 63 sets the
sign bit of slice 0. Unsetting the last bit in an existing slice leaves its value
at zero. Slices that were never set can be absent.
docker run --rm -v "$PWD":/usr/src/infinite-bitmask -w /usr/src/infinite-bitmask php:8.3-cli php example/example.phpStored slice 0: 3
Stored slice 2: 1
Create: yes
Read: yes
Delete: no
ViewAuditLog: yes
For complete tests running just call composer exec phpunit or use
docker run -it --rm -v "$PWD":/usr/src/infinite-bitmask -w /usr/src/infinite-bitmask php:8.3-cli php ./vendor/bin/phpunitThis software is distributed under MIT license.