Download the PHP package codekandis/phlags without Composer
On this page you can find all versions of the php package codekandis/phlags. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codekandis/phlags
More information about codekandis/phlags
Files in codekandis/phlags
Package phlags
Short Description Introduces the possibility to use flagable enums in PHP.
License MIT
Informations about the package phlags
codeKandis/phlags
codekandis/phlags
introduces the possibility to use flagable enums in PHP.
Index
- Installation
- Testing
- How to use
- Declaration
- General hints
- Instantiation
- Reading
- Determination
- Manipulation
- Fluent Manipulation
- String Representation
- Traitful Extensions
- Conditional Manipulation
- Validation
- Flagables
- Values
Installation
Install the latest version with
Testing
Test the code with
How to use
Example: Simple permissions in a file system
Declaration
Declare a class extending the flagable base class AbstractFlagable
.
General Hints
In the context of manipulating the flagable the following values are supposed to be equal and can similarly passed to all methods of the flagable.
In the other hand the type restriction of PHP does not allow any combination of an integer value with a string with a flagable.
Instantiation
You can easily instantiate your flagable in different ways.
Reading
You can read the value of the flagable in 2 different ways.
Determination
You can determine if one or more specific flags have been set.
Manipulation
You can set, unset and switch flags.
Fluent Manipulation
The base class AbstractFlagable
implements the fluent interface. So the manipulation of the flagable can be chained.
String Representation
A flagable can stringified in different ways with different outputs.
Traitful Extensions
To keep the simplicity and performance Phlags provides Traitful Extensions
. Instead of implementing a complex and heavyweight inheritance you can combine the extensions of your choice into the flagable of your needs.
Conditional Manipulation
— ConditionalManipulationExtension
The Conditional Manipulation provides you with methods to set, unset and switch a flag value while a passed statement must evaluate to true.
Validation
Flagables
While instantiating your very first flagable your flagable has to pass a one-time validation.
- all declared constants are an
unsigned integer
- all constants are a power of 2
- there is no duplicates of any of the constant values
- there is no missing values, e. g. a flagable with a flags set
1, 2, 8
ist invalid, while the flag4
is missing
If the flagable does not pass the validation an InvalidFlagableException
will be thrown and you can retreive an array of detailed error messages of the validation.
Values
A flag value passed to the methods of the flagable has to pass a validation on every method call.
- it is an
unsigned integer
less or equal than the maximum value of the called flagable - it is a
string
representation of a flagable with an identic type as the type of the called flagable - it is a flagable with an identic type as the type of the called flagable
- it does not exceeds the maximum flag value of the called flagable
If the value does not pass the validation an InvalidValueException
will be thrown and you can retreive an array of detailed error messages of the validation.