https://github.com/phoenixrvd/bitmask
Simple bitmask utility
https://github.com/phoenixrvd/bitmask
bitmask clean-code mit open-source php-library php7 php71 php72
Last synced: 7 months ago
JSON representation
Simple bitmask utility
- Host: GitHub
- URL: https://github.com/phoenixrvd/bitmask
- Owner: phoenixrvd
- License: mit
- Created: 2018-06-21T22:10:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-07T08:00:44.000Z (over 6 years ago)
- Last Synced: 2025-01-30T05:26:38.247Z (8 months ago)
- Topics: bitmask, clean-code, mit, open-source, php-library, php7, php71, php72
- Language: PHP
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bitmask
[](https://php.net/)
[](https://packagist.org/packages/phoenixrvd/bitmask)
[](https://packagist.org/packages/phoenixrvd/bitmask)
[](https://packagist.org/packages/phoenixrvd/bitmask)[](https://travis-ci.org/phoenixrvd/bitmask)
[](https://codeclimate.com/github/phoenixrvd/bitmask)
[](https://styleci.io/repos/138226713)
[](https://codeclimate.com/github/phoenixrvd/bitmask/coverage)
[](https://bettercodehub.com/results/phoenixrvd/bitmask)
[](https://packagist.org/packages/phoenixrvd/bitmask)- [Installation](#installation)
- [Example](#example)
- [Testing](#testing)
- [Copyright and license](#copyright-and-license)In PHP a number is (mostly) 4 Bytes long. This means that one number actually uses 32 bits of the internal storage.
In this case 32 boolean values can be stored as single integer. The problem ist a 'magic numbers'.
## Installation
Install the latest version with
```bash
composer require phoenixrvd/bitmask
```
## ExampleWithout this API [before.php](examples/before.php)
```php
fromInt(6);if($activeFeatures->isOn(StateMap::OPTION_1)){
// Do this
}if($activeFeatures->isOff(StateMap::OPTION_2)) {
// Do that
}// Activate options
$activeFeatures->on(StateMap::OPTION_5, StateMap::OPTION_6);// Deactivate options
$activeFeatures->off(StateMap::OPTION_4, StateMap::OPTION_1);
```## Testing
```bash
composer bitmask:test
```## Copyright and license
Code released under the [MIT License](LICENSE).