2017 © Pedro Peláez
 

library mahana-bitmask

Bit masking to manage settings

image

jrmadsen67/mahana-bitmask

Bit masking to manage settings

  • Saturday, October 1, 2016
  • by jrmadsen67
  • Repository
  • 1 Watchers
  • 12 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

MahanaBitfield

Bit masking to manage settings. Rather than having a few dozen flags on every table, bit masking can be used to reduce them to a single integer value., (*1)

Installation

composer require jrmadsen67/mahana-bitmask

Usage

Typically we would use this in conjunction with an MVC model class, so I will use that scenario as an example., (*2)

MahanaBitfield is an abstract class, so you will create a simple inherited class for each setting field you wish to have., (*3)

This means that if you have a Users table and want to store settings in a field, you would make a class like this example:, (*4)

use jrmadsen67\MahanaBitfield\MahanaBitfield;

class UserSettings extends MahanaBitfield
{
    public $flags = [
        'flag1' => 0,
        'flag2' => 1,
        'flag3' => 2,
    ];
}

Notice that this DOES NOT work directly with your model; you will have to get/set the settings field yourself in a normal manner for your framework or code., (*5)

To initialize a class:, (*6)

$mbf = new UserSettings;, (*7)

To set a particular flag to true/false, (*8)

$mbf->flag1 = true;, (*9)

To get a particular setting value, (*10)

$flag1 = $mbf->flag1;, (*11)

To get the bitmask value, (*12)

$settings = $mbf->getValue();, (*13)

Use setFlags() & getFlags() to work with the whole array at once, (*14)

$userSettings = new UserSettings;

$userSettings->setFlags([
    'flag2' => true,
    'flag3' => true,
]);

or, (*15)

$setting_array = $userSettings->getFlags();

/*

var_dump($setting_array);

array(
    'flag2' => true,
    'flag3' => true,
);

*/

The tests can provide you with more examples. Questions and PRs welcome!, (*16)

The Versions

01/10 2016

dev-master

9999999-dev https://github.com/jrmadsen67/mahana-bitmask

Bit masking to manage settings

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

settings bit masking

27/09 2016

v1.0.0

1.0.0.0 https://github.com/jrmadsen67/mahana-bitmask

Bit masking to manage settings

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

settings bit masking