gksh / bitmask
A bitmask value object for PHP
Fund package maintenance!
karkowg
Requires
- php: ^8.2.0
Requires (Dev)
- laravel/pint: ^1.13.7
- pestphp/pest: ^2.28.1
- phpstan/phpstan: ^1.10.50
- rector/rector: ^0.19.8
- symfony/var-dumper: ^6.4.0|^7.0.0
README
gksh/bitmask
A simple way to use bitmask and bitwise operations in PHP.
Installation
Requires PHP 8.2+
composer require gksh/bitmask
🧪 Usage
Streamline flag handling by encoding boolean options into simple integers through bitmasking.
Please see ide.php for full example and playground for more.
enum Panel: int { case Project = 1; case Terminal = 2; case SourceControl = 4; case Extensions = 8; } class Panels extends TinyBitmask { public function isVisible(Panel $panel): bool { return $this->has($panel->value); } public function togglePanel(Panel $panel): Panels { return $this->toggle($panel->value); } } class Ide { public Panels $panels; public function togglePanel(Panel $panel): self { $this->panels->togglePanel($panel); return $this; } } $ide = (new Ide()) ->togglePanel(Panel::Project) ->togglePanel(Panel::Terminal); $ide->panels->isVisible(Panel::Terminal); // true $ide->panels->isVisible(Panel::Extensions); // false
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.