Download the PHP package icecave/flip without Composer
On this page you can find all versions of the php package icecave/flip. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package flip
Flip
Flip is a tiny PHP library for working with strict sets of boolean flags.
- Install via Composer package icecave/flip
- Read the API documentation
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.
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.
Creating a flag-set
The flag-set trait provides the following static methods for quickly creating common sets:
defaults()
- creates a flag-set where all flags are set to the default valuesall()
- creates a flag-set where all flags are set totrue
none()
- creates a flag-set where all flags are set tofalse
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
.
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:
Flag-sets are immutable, each call to the fluent interface returns a new instance with the updated flag value.
Flags can not be named "defaults", "all" or "none".
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.
It is not possible to set flags using the property notation.
Contact us
- Follow @IcecaveStudios on Twitter
- Visit the Icecave Studios website