BitFlagTrait
Trait providing common methods for bitmask flag enumerations.
Classes using this trait MUST define the following constants:
ALL(int)FLAGS(array) FLAGS_NAME(array<int, string>)
The NONE constant (no flag set) is provided by the trait, as it is always 0
for any bitmask.
Tags
Table of Contents
Constants
- NONE : int = 0
- Do nothing.
Methods
- describe() : string
- Gets a human-readable description of the flags in a bitmask.
- getFlags() : array<string|int, int>
- Gets a list of all individual flags present in a bitmask.
- has() : bool
- Checks whether a specific flag is set in a bitmask.
- isValid() : bool
- Validates that a bitmask contains only valid flags.
Constants
NONE
Do nothing.
public
int
NONE
= 0
Methods
describe()
Gets a human-readable description of the flags in a bitmask.
public
static describe(int $mask[, string $separator = ', ' ]) : string
Parameters
- $mask : int
- $separator : string = ', '
Return values
stringgetFlags()
Gets a list of all individual flags present in a bitmask.
public
static getFlags(int $mask) : array<string|int, int>
Parameters
- $mask : int
Return values
array<string|int, int>has()
Checks whether a specific flag is set in a bitmask.
public
static has(int $mask, int $flag) : bool
Parameters
- $mask : int
- $flag : int
Return values
boolisValid()
Validates that a bitmask contains only valid flags.
public
static isValid(int $mask) : bool
Parameters
- $mask : int