zorro provides utilities and components for building and managing object-oriented bitmasks.
Requires php 8.1 or later.
Recommended installation method is via Composer: simply composer install php-enspired/zorro
<?php
use at\zorro\IsBitmask;
enum Option : int {
use IsBitmask;
case FOO = 1;
case BAR = 1<<1;
case BAZ = 1<<2;
}
$opts = Option::buildFrom(Option::FOO, Option::BAZ);
echo "option 'FOO' is ", Option::FOO->in($opts) ? "enabled" : "disabled", " in \$opts\n";
echo "option 'BAR' is ", Option::BAR->in($opts) ? "enabled" : "disabled", " in \$opts\n";
echo "option 'BAZ' is ", Option::BAZ->in($opts) ? "enabled" : "disabled", " in \$opts\n";
$opts = Option::BAR->on($opts);
$opts = Option::BAZ->off($opts);
echo "option 'FOO' is ", Option::FOO->in($opts) ? "enabled" : "disabled", " in \$opts\n";
echo "option 'BAR' is ", Option::BAR->in($opts) ? "enabled" : "disabled", " in \$opts\n";
echo "option 'BAZ' is ", Option::BAZ->in($opts) ? "enabled" : "disabled", " in \$opts\n";
…coming soon
- run unit tests with
composer test:unit
- run static analysis with
composer test:analyze
I'm on IRC at libera#php-enspired
, or open an issue on github. Feedback is welcomed as well.