An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Bitmask

[![Minimum PHP Version](https://img.shields.io/badge/php->=7.0-8892BF.svg)](https://php.net/)
[![Latest Stable Version](https://poser.pugx.org/phoenixrvd/bitmask/v/stable.svg)](https://packagist.org/packages/phoenixrvd/bitmask)
[![composer.lock](https://poser.pugx.org/phoenixrvd/bitmask/composerlock)](https://packagist.org/packages/phoenixrvd/bitmask)
[![License](https://poser.pugx.org/phoenixrvd/bitmask/license)](https://packagist.org/packages/phoenixrvd/bitmask)

[![Build Status](https://travis-ci.org/phoenixrvd/bitmask.png?branch=master)](https://travis-ci.org/phoenixrvd/bitmask)
[![Code Climate](https://codeclimate.com/github/phoenixrvd/bitmask.png)](https://codeclimate.com/github/phoenixrvd/bitmask)
[![StyleCI](https://styleci.io/repos/138226713/shield?branch=master)](https://styleci.io/repos/138226713)
[![Test Coverage](https://codeclimate.com/github/phoenixrvd/bitmask/badges/coverage.svg)](https://codeclimate.com/github/phoenixrvd/bitmask/coverage)
[![BCH compliance](https://bettercodehub.com/edge/badge/phoenixrvd/bitmask)](https://bettercodehub.com/results/phoenixrvd/bitmask)
[![Latest Unstable Version](https://poser.pugx.org/phoenixrvd/bitmask/v/unstable.svg)](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
```
## Example

Without 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).