RouteFlag uses ConstantsTrait
Bitmask flags describing which HTTP routes a resource exposes.
Each constant (COUNT, DELETE, GET, LIST, PATCH, POST, PUT, ...)
represents an individual route that can be toggled independently, and several
convenient presets are provided (DEFAULT, READ_ONLY, WRITE, CRUD).
Flags are combined with the bitwise OR operator and inspected through the
helper methods of this class.
The class also bridges the legacy boolean-array configuration format to the modern bitmask via RouteFlag::convertLegacyArray().
Tags
Table of Contents
Constants
- ALL : int = self::COUNT | self::DELETE | self::DELETE_MULTI...
- All valid flags combined (used for validation)
- COUNT : int = 1 << 0
- Enable COUNT route
- CRUD : int = self::GET | self::LIST | self::POST | self::PUT...
- Basic CRUD without count
- DEFAULT : int = self::COUNT | self::DELETE | self::DELETE_MULTI...
- Default routes: all CRUD operations enabled
- DEFAULT_FLAG : string = 'defaultFlag'
- DELETE : int = 1 << 1
- Enable DELETE route
- DELETE_MULTIPLE : int = 1 << 2
- Enable DELETE with multiple IDs support
- FLAGS : array<string|int, mixed> = [self::COUNT, self::DELETE, self::DELETE_MULTIP...
- The default list of flags.
- FLAGS_NAME : array<string|int, mixed> = [self::COUNT => 'COUNT', self::DELETE => 'DELET...
- The list of flag's name.
- GET : int = 1 << 3
- Enable GET route
- HAS_COUNT : string = 'hasCount'
- HAS_DELETE : string = 'hasDelete'
- HAS_DELETE_MULTIPLE : string = 'hasDeleteMultiple'
- HAS_GET : string = 'hasGet'
- HAS_LIST : string = 'hasList'
- HAS_PATCH : string = 'hasPatch'
- HAS_POST : string = 'hasPost'
- HAS_PUT : string = 'hasPut'
- LIST : int = 1 << 4
- Enable LIST route
- NONE : int = 0
- No routes enabled
- PATCH : int = 1 << 5
- Enable PATCH route
- POST : int = 1 << 6
- Enable POST route
- PUT : int = 1 << 7
- Enable PUT route
- READ_ONLY : int = self::GET | self::LIST | self::COUNT
- Read-only routes (GET, LIST, COUNT)
- WRITE : int = self::POST | self::PUT | self::PATCH | self::DE...
- Write routes (POST, PUT, PATCH, DELETE)
Methods
- convertLegacyArray() : int
- Converts legacy boolean array format to bitmask.
- 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 RouteFlag values.
Constants
ALL
All valid flags combined (used for validation)
public
int
ALL
= self::COUNT | self::DELETE | self::DELETE_MULTIPLE | self::GET | self::LIST | self::PATCH | self::POST | self::PUT
COUNT
Enable COUNT route
public
int
COUNT
= 1 << 0
CRUD
Basic CRUD without count
public
int
CRUD
= self::GET | self::LIST | self::POST | self::PUT | self::DELETE
DEFAULT
Default routes: all CRUD operations enabled
public
int
DEFAULT
= self::COUNT | self::DELETE | self::DELETE_MULTIPLE | self::GET | self::LIST | self::PATCH | self::POST | self::PUT
DEFAULT_FLAG
public
string
DEFAULT_FLAG
= 'defaultFlag'
DELETE
Enable DELETE route
public
int
DELETE
= 1 << 1
DELETE_MULTIPLE
Enable DELETE with multiple IDs support
public
int
DELETE_MULTIPLE
= 1 << 2
FLAGS
The default list of flags.
public
array<string|int, mixed>
FLAGS
= [self::COUNT, self::DELETE, self::DELETE_MULTIPLE, self::GET, self::LIST, self::PATCH, self::POST, self::PUT]
FLAGS_NAME
The list of flag's name.
public
array<string|int, mixed>
FLAGS_NAME
= [self::COUNT => 'COUNT', self::DELETE => 'DELETE', self::DELETE_MULTIPLE => 'DELETE_MULTIPLE', self::GET => 'GET', self::LIST => 'LIST', self::PATCH => 'PATCH', self::POST => 'POST', self::PUT => 'PUT']
GET
Enable GET route
public
int
GET
= 1 << 3
HAS_COUNT
public
string
HAS_COUNT
= 'hasCount'
HAS_DELETE
public
string
HAS_DELETE
= 'hasDelete'
HAS_DELETE_MULTIPLE
public
string
HAS_DELETE_MULTIPLE
= 'hasDeleteMultiple'
HAS_GET
public
string
HAS_GET
= 'hasGet'
HAS_LIST
public
string
HAS_LIST
= 'hasList'
HAS_PATCH
public
string
HAS_PATCH
= 'hasPatch'
HAS_POST
public
string
HAS_POST
= 'hasPost'
HAS_PUT
public
string
HAS_PUT
= 'hasPut'
LIST
Enable LIST route
public
int
LIST
= 1 << 4
NONE
No routes enabled
public
int
NONE
= 0
PATCH
Enable PATCH route
public
int
PATCH
= 1 << 5
POST
Enable POST route
public
int
POST
= 1 << 6
PUT
Enable PUT route
public
int
PUT
= 1 << 7
READ_ONLY
Read-only routes (GET, LIST, COUNT)
public
int
READ_ONLY
= self::GET | self::LIST | self::COUNT
WRITE
Write routes (POST, PUT, PATCH, DELETE)
public
int
WRITE
= self::POST | self::PUT | self::PATCH | self::DELETE | self::DELETE_MULTIPLE
Methods
convertLegacyArray()
Converts legacy boolean array format to bitmask.
public
static convertLegacyArray([array<string|int, mixed> $init = [] ]) : int
Parameters
- $init : array<string|int, mixed> = []
-
Legacy initialization array
Return values
int —The resulting bitmask
describe()
Gets a human-readable description of the flags in a bitmask.
public
static describe(int $mask[, string $separator = ', ' ]) : string
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>
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
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 RouteFlag values.
public
static isValid(int $mask) : bool
Parameters
- $mask : int
-
The bitmask value to validate.
Tags
Return values
bool —Returns true if the mask contains only valid flags, false otherwise.