BaseEnum
API reference › HTML Helper › Base › BaseEnum
1 subclass
Provides reusable normalization helpers for enum and scalar values.
BackedEnum for enums with scalar values.
UnitEnum for all enum types.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
normalizeArray() static | Normalizes an array of enum values or mixed values to their scalar values or names. | BaseEnum |
normalizeStringArray() static | Normalizes an array of enum values or mixed values to string representations. | BaseEnum |
normalizeStringValue() static | Normalizes a single enum value or mixed value to a string representation. | BaseEnum |
normalizeValue() static | Normalizes a single enum value to its scalar value or name. | BaseEnum |
Method details
Section titled “Method details”normalizeArray()
Section titled “normalizeArray() ”public static function normalizeArray(mixed[] $values): mixed[]Normalizes an array of enum values or mixed values to their scalar values or names.
Applies normalizeValue() to each element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | mixed[] | Array of enum instances or mixed values to normalize. |
Returns
mixed[]: Array of normalized scalar values, names, or original values for non-enums. normalizeValue() for single value normalization.
Throws
InvalidArgumentException: if any value is not an enum, scalar, array, ornull.
normalizeStringArray()
Section titled “normalizeStringArray() ”public static function normalizeStringArray(mixed[] $values): string[]Normalizes an array of enum values or mixed values to string representations.
Applies normalizeStringValue() to each element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | mixed[] | Array of enum instances or mixed values to normalize. |
Returns
string[]: Array of normalized string representations. normalizeStringValue() for single value string normalization.
Throws
InvalidArgumentException: if any value is not an enum, scalar, array, ornull.
normalizeStringValue()
Section titled “normalizeStringValue() ”public static function normalizeStringValue(mixed $value): stringNormalizes a single enum value or mixed value to a string representation.
Converts null to null, booleans to true or false, and arrays to Array for deterministic textual
output.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Value to normalize. |
Returns
string: Normalized string representation. normalizeStringArray() for batch string normalization.
Throws
InvalidArgumentException: if the value is not an enum, scalar, array, ornull.
normalizeValue()
Section titled “normalizeValue() ”public static function normalizeValue(mixed $value): ($value is UnitEnum ? int|string : ($value is string ? string : bool|float|int|mixed[]|null))Normalizes a single enum value to its scalar value or name.
Returns the original value unchanged for non-enum input.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Value to normalize. |
Returns
($value is UnitEnum ? int|string : ($value is string ? string : bool|float|int|mixed[]|null)): Scalar value for BackedEnum, name for pure enums, or the original value for non-enums. normalizeArray() for batch normalization.
Throws
InvalidArgumentException: if the value is not an enum, scalar, array, ornull.