2017 © Pedro Peláez
 

library flip

A tiny library for working with strict sets of boolean values.

image

icecave/flip

A tiny library for working with strict sets of boolean values.

  • Thursday, November 19, 2015
  • by jmalloc
  • Repository
  • 1 Watchers
  • 2 Stars
  • 511 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Flip

![The most recent stable version is 0.2.0][version-image] Current build status image ![Current coverage status image][coverage-image], (*1)

Flip is a tiny PHP library for working with strict sets of boolean flags., (*2)

Defining a flag-set

A flag-set describes the available flags of a given type. Flag-sets are defined by declaring a class that uses the FlagSetTrait trait., (*3)

Each property in the class defines a named flag that can be set to true or false. All properties must be private and have a default boolean value., (*4)

use Icecave\Flip\FlagSetTrait;

final class ExampleFlags
{
    use FlagSetTrait;

    private $foo = true;
    private $bar = false;
    private $baz = false;
}

Creating a flag-set

The flag-set trait provides the following static methods for quickly creating common sets:, (*5)

  • defaults() - creates a flag-set where all flags are set to the default values
  • all() - creates a flag-set where all flags are set to true
  • none() - creates a flag-set where all flags are set to false

Flag-sets can also be created and modified using a fluent interface. The example below creates a flag-set with only the bar and baz properties set to true., (*6)

$flags = ExampleFlags::none()
    ->bar(true)
    ->baz(true);

Omitting the initial call to defaults(), all() or none() is short-hand for using the defaults. This means that the following two examples are equivalent:, (*7)

$flags = ExampleFlags::defaults()
    ->foo(false)
    ->bar(true);
$flags = ExampleFlags
    ::foo(false)
    ->bar(true);

Flag-sets are immutable, each call to the fluent interface returns a new instance with the updated flag value., (*8)

Flags can not be named "defaults", "all" or "none"., (*9)

Using a flag-set

Functions that accept flag-sets as parameters can use a type-hint. Flags are read using the regular PHP property notation. Flag values are guaranteed to be a boolean., (*10)

function dumpFlags(ExampleFlags $flags)
{
    if ($flags->foo) {
        echo 'Foo is enabled!';
    } else {
        echo 'Foo is disabled!';
    }

    if ($flags->bar) {
        echo 'Bar is enabled!';
    } else {
        echo 'Bar is disabled!';
    }

    if ($flags->baz) {
        echo 'Baz is enabled!';
    } else {
        echo 'Baz is disabled!';
    }
}

It is not possible to set flags using the property notation., (*11)

Contact us

The Versions

19/11 2015

dev-develop

dev-develop https://github.com/IcecaveStudios/flip

A tiny library for working with strict sets of boolean values.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

field enum bit set option boolean flag

19/11 2015

dev-master

9999999-dev https://github.com/IcecaveStudios/flip

A tiny library for working with strict sets of boolean values.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

field enum bit set option boolean flag

19/11 2015

0.2.0

0.2.0.0 https://github.com/IcecaveStudios/flip

A tiny library for working with strict sets of boolean values.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

field enum bit set option boolean flag

17/11 2015

0.1.0

0.1.0.0 https://github.com/IcecaveStudios/flip

A tiny library for working with strict sets of boolean values.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

field enum bit set option boolean flag