Oihana PHP

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
example
use oihana\core\arrays\CleanFlag;

// Combine multiple flags
$mask = CleanFlag::NULLS | CleanFlag::EMPTY | CleanFlag::TRIM ;

// Check flags
CleanFlag::has($mask, CleanFlag::NULLS) ; // true
CleanFlag::has($mask, CleanFlag::RECURSIVE) ; // false

Table of Contents

Constants

ALL  = self::NULLS | self::EMPTY | self::TRIM | self::RECURSIVE | self::EMPTY_ARR | self::FALSY | self::RETURN_NULL
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, self::RETURN_NULL]
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', self::RETURN_NULL => 'RETURN_NULL']
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)
NORMALIZE  = self::DEFAULT | \oihana\core\arrays\CleanFlag::RETURN_NULL
Default cleaning: remove nulls, empty/trim strings, empty arrays recursively and return null if empty.
NULLS  = 1 << 0
Remove null values
RECURSIVE  = 1 << 3
Clean nested arrays recursively
RETURN_NULL  = 1 << 6
Return null instead of empty array when result is empty
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 flags.

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 | self::RETURN_NULL

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, self::RETURN_NULL]

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', self::RETURN_NULL => 'RETURN_NULL']

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

NORMALIZE

Default cleaning: remove nulls, empty/trim strings, empty arrays recursively and return null if empty.

public mixed 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
string

getFlags()

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
bool

isValid()

Validates that a bitmask contains only valid flags.

public static isValid(int $mask) : bool
Parameters
$mask : int
Return values
bool

        
On this page

Search results