CleanFlag
Enumeration representing cleaning modes as bit flags.
Each flag can be combined using the bitwise OR operator (|
) to form a mask.
The has()
helper can be used to check if a particular flag is present in a mask.
Tags
Table of Contents
Constants
- ALL = self::NULLS | self::EMPTY | self::TRIM | self::RECURSIVE | self::EMPTY_ARR | self::FALSY
- All valid flags combined (used for validation)
- DEFAULT = self::NULLS | self::EMPTY | self::TRIM | self::RECURSIVE | self::EMPTY_ARR
- Default cleaning: remove nulls, empty/trim strings, empty arrays recursively
- EMPTY = 1 << 1
- Remove empty strings ''
- EMPTY_ARR = 1 << 4
- Remove empty arrays (after recursive cleaning)
- FALSY = 1 << 5
- Remove the falsy values : '0', false, .
- FLAGS = [self::NULLS, self::EMPTY, self::TRIM, self::RECURSIVE, self::EMPTY_ARR, self::FALSY]
- The default list of flags.
- FLAGS_NAME = [self::NULLS => 'NULLS', self::EMPTY => 'EMPTY', self::TRIM => 'TRIM', self::RECURSIVE => 'RECURSIVE', self::EMPTY_ARR => 'EMPTY_ARR', self::FALSY => 'FALSY']
- The list of flag's name.
- MAIN = self::NULLS | self::EMPTY | self::EMPTY_ARR | self::TRIM
- All the main flags.
- NONE = 0
- No cleaning (edge case, returns original array)
- NULLS = 1 << 0
- Remove null values
- RECURSIVE = 1 << 3
- Clean nested arrays recursively
- TRIM = 1 << 2
- Treat whitespace-only strings as empty (implies CLEAN_EMPTY)
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 CleanFlag values.
Constants
ALL
All valid flags combined (used for validation)
public
mixed
ALL
= self::NULLS | self::EMPTY | self::TRIM | self::RECURSIVE | self::EMPTY_ARR | self::FALSY
DEFAULT
Default cleaning: remove nulls, empty/trim strings, empty arrays recursively
public
mixed
DEFAULT
= self::NULLS | self::EMPTY | self::TRIM | self::RECURSIVE | self::EMPTY_ARR
EMPTY
Remove empty strings ''
public
int
EMPTY
= 1 << 1
EMPTY_ARR
Remove empty arrays (after recursive cleaning)
public
int
EMPTY_ARR
= 1 << 4
FALSY
Remove the falsy values : '0', false, .
public
int
FALSY
= 1 << 5
..
FLAGS
The default list of flags.
public
mixed
FLAGS
= [self::NULLS, self::EMPTY, self::TRIM, self::RECURSIVE, self::EMPTY_ARR, self::FALSY]
FLAGS_NAME
The list of flag's name.
public
mixed
FLAGS_NAME
= [self::NULLS => 'NULLS', self::EMPTY => 'EMPTY', self::TRIM => 'TRIM', self::RECURSIVE => 'RECURSIVE', self::EMPTY_ARR => 'EMPTY_ARR', self::FALSY => 'FALSY']
MAIN
All the main flags.
public
mixed
MAIN
= self::NULLS | self::EMPTY | self::EMPTY_ARR | self::TRIM
NONE
No cleaning (edge case, returns original array)
public
int
NONE
= 0
NULLS
Remove null values
public
int
NULLS
= 1 << 0
RECURSIVE
Clean nested arrays recursively
public
int
RECURSIVE
= 1 << 3
TRIM
Treat whitespace-only strings as empty (implies CLEAN_EMPTY)
public
int
TRIM
= 1 << 2
Methods
describe()
Gets a human-readable description of the flags in a bitmask.
public
static describe(int $mask[, string $separator = ', ' ]) : string
This method provides a string representation of which flags are active, useful for debugging, logging, or user interfaces.
Parameters
- $mask : int
-
The bitmask value to describe.
- $separator : string = ', '
-
The separator between the flag descriptions.
Tags
Return values
string —A comma-separated (by default) string of flag names.
getFlags()
Gets a list of all individual flags present in a bitmask.
public
static getFlags(int $mask) : array<string|int, int>
This method decomposes a bitmask into its individual flag components, useful for debugging or logging which flags are active.
Parameters
- $mask : int
-
The bitmask value to decompose.
Tags
Return values
array<string|int, int> —An array of individual flag values present in the mask.
has()
Checks whether a specific flag is set in a bitmask.
public
static has(int $mask, int $flag) : bool
This method is useful when using the CleanFlag enum as a set of bit flags.
You can combine multiple flags using the bitwise OR operator (|
) and then
check if a particular flag is present in the combined mask.
Parameters
- $mask : int
-
The bitmask value, potentially containing multiple flags combined with
|
. - $flag : int
-
The specific flag to check for in the mask.
Tags
Return values
bool —Returns true
if the given flag is present in the mask, false
otherwise.
isValid()
Validates that a bitmask contains only valid CleanFlag values.
public
static isValid(int $mask) : bool
This method checks if the provided mask consists only of recognized flags. Any bits set outside of the valid flag range will cause validation to fail.
Parameters
- $mask : int
-
The bitmask value to validate.
Tags
Return values
bool —Returns true
if the mask contains only valid flags, false
otherwise.