PHP code example of phoenixrvd / bitmask

1. Go to this page and download the library: Download phoenixrvd/bitmask library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phoenixrvd / bitmask example snippets




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'.



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);