2017 © Pedro Peláez
 

utility bitmask

bitmask utility package

image

phoenixrvd/bitmask

bitmask utility package

  • Friday, June 22, 2018
  • by PhoenixRVD
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Bitmask

Minimum PHP Version Latest Stable Version composer.lock License, (*1)

Build Status Code Climate StyleCI Test Coverage BCH compliance Latest Unstable Version, (*2)

, (*3)

In PHP a number is (mostly) 4 Bytes long. This means that one number actually uses 32 bits of the internal storage., (*4)

In this case 32 boolean values can be stored as single integer. The problem ist a 'magic numbers'., (*5)

Installation

Install the latest version with, (*6)

composer require phoenixrvd/bitmask

Example

Without this API before.php, (*7)

<?php

class StateMap {
    const OPTION_1 = 1;
    const OPTION_2 = 2;
    const OPTION_4 = 4;
    // What is next ????
}

// Check for Active Feature
$activeFeatures = 6;

if(($activeFeatures & StateMap::OPTION_1) === StateMap::OPTION_1){
    // Do this
}

if(($activeFeatures & StateMap::OPTION_2) !== StateMap::OPTION_2) {
    // Do this
}

// Activation and deactivation from options ist not 'Human Readable'.

With this API after.php, (*8)

<?php

class StateMap {
    const OPTION_1 = 0;
    const OPTION_2 = 1;
    const OPTION_4 = 2;
    const OPTION_5 = 3;
    const OPTION_6 = 4;
}

// Check for Active Feature
$activeFeatures = (new \PhoenixRVD\Bitmask\BitmaskFactory())->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

composer bitmask:test

Code released under the MIT License., (*9)

The Versions

22/06 2018

dev-master

9999999-dev

bitmask utility package

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Viacheslav Wolf

22/06 2018

1.0.2

1.0.2.0

bitmask utility package

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Viacheslav Wolf

22/06 2018

1.0.1

1.0.1.0

bitmask utility package

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Viacheslav Wolf