CleanFlag uses BitFlagTrait
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 : int = self::NULLS | self::EMPTY | self::TRIM | self::...
- All valid flags combined (used for validation)
- DEFAULT : int = self::NULLS | self::EMPTY | self::TRIM | self::...
- Default cleaning: remove nulls, empty/trim strings, empty arrays recursively
- EMPTY : int = 1 << 1
- Remove empty strings ''
- EMPTY_ARR : int = 1 << 4
- Remove empty arrays (after recursive cleaning)
- FALSY : int = 1 << 5
- Remove the falsy values : '0', false, .
- FLAGS : array<string|int, mixed> = [self::NULLS, self::EMPTY, self::TRIM, self::RE...
- The default list of flags.
- FLAGS_NAME : array<string|int, mixed> = [self::NULLS => 'NULLS', self::EMPTY => 'EMPTY'...
- The list of flag's name.
- MAIN : int = self::NULLS | self::EMPTY | self::EMPTY_ARR | s...
- All the main flags.
- NONE : int = 0
- Do nothing.
- NORMALIZE : int = self::DEFAULT | \oihana\core\arrays\CleanFlag::...
- Default cleaning: remove nulls, empty/trim strings, empty arrays recursively and return null if empty.
- NULLS : int = 1 << 0
- Remove null values
- RECURSIVE : int = 1 << 3
- Clean nested arrays recursively
- RETURN_NULL : int = 1 << 6
- Return null instead of empty array when result is empty
- TRIM : int = 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 flags.
Constants
ALL
All valid flags combined (used for validation)
public
int
ALL
= self::NULLS | self::EMPTY | self::TRIM | self::RECURSIVE | self::EMPTY_ARR | self::FALSY | self::RETURN_NULL
DEFAULT
Default cleaning: remove nulls, empty/trim strings, empty arrays recursively
public
int
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
array<string|int, mixed>
FLAGS
= [self::NULLS, self::EMPTY, self::TRIM, self::RECURSIVE, self::EMPTY_ARR, self::FALSY, self::RETURN_NULL]
FLAGS_NAME
The list of flag's name.
public
array<string|int, mixed>
FLAGS_NAME
= [self::NULLS => 'NULLS', self::EMPTY => 'EMPTY', self::TRIM => 'TRIM', self::RECURSIVE => 'RECURSIVE', self::EMPTY_ARR => 'EMPTY_ARR', self::FALSY => 'FALSY', self::RETURN_NULL => 'RETURN_NULL']
MAIN
All the main flags.
public
int
MAIN
= self::NULLS | self::EMPTY | self::EMPTY_ARR | self::TRIM
NONE
Do nothing.
public
int
NONE
= 0
NORMALIZE
Default cleaning: remove nulls, empty/trim strings, empty arrays recursively and return null if empty.
public
int
NORMALIZE
= self::DEFAULT | \oihana\core\arrays\CleanFlag::RETURN_NULL
NULLS
Remove null values
public
int
NULLS
= 1 << 0
RECURSIVE
Clean nested arrays recursively
public
int
RECURSIVE
= 1 << 3
RETURN_NULL
Return null instead of empty array when result is empty
public
int
RETURN_NULL
= 1 << 6
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
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