Skip to content

About

Infinite bitmask implementation

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Infinite bitmask implementation

License Packagist PHP Version Code Coverage

About

Based on Aliance/Bitmask, but without max bits' limitation.

Installation

Install the latest version with composer:

composer require aliance/infinite-bitmask

If you checkout this library for testing purposes, install its dependencies:

docker run --rm -it --volume $PWD:/app -u $(id -u):$(id -g) composer:2 i

Usage

use 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.php
Stored slice 0: 3
Stored slice 2: 1
Create: yes
Read: yes
Delete: no
ViewAuditLog: yes

Tests

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/phpunit

License

This software is distributed under MIT license.

About

Infinite bitmask implementation

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages