BaseCSSClass
API reference › HTML Helper › Base › BaseCSSClass
1 subclass
Provides reusable normalization and validation for HTML class attributes.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
add() static | Adds one or more CSS classes to an attribute array with validation and merging logic. | BaseCSSClass |
render() static | Renders a validated CSS class name using a base format and an allowed value list. | BaseCSSClass |
Method details
Section titled “Method details”add()
Section titled “add() ”public static function add(mixed[] &$attributes, mixed[]|string|Stringable|UnitEnum|null $classes, bool $override = false): voidAdds one or more CSS classes to an attribute array with validation and merging logic.
Replaces the existing class attribute when $override is true; otherwise merges unique class names.
Parameters
| Parameter | Type | Description |
|---|---|---|
$attributes | mixed[] | Attribute array to modify. Passed by reference and updated in place. |
$classes | mixed[]|Stringable|UnitEnum| | Classes to add. |
$override | bool | Whether to override (true) or merge (false, default) with existing classes. |
render()
Section titled “render() ”public static function render(string|UnitEnum $class, string $baseClass, list<scalar|UnitEnum|null> $allowed): stringRenders a validated CSS class name using a base format and an allowed value list.
Validates the value against $allowed and renders it with sprintf().
Parameters
| Parameter | Type | Description |
|---|---|---|
$class | string|UnitEnum | Class value to validate and render. |
$baseClass | string | Base class format string (for example, btn-%s). |
$allowed | list<scalar|UnitEnum| | List of allowed class values for validation. |
Returns
string: Formatted and validated CSS class name. Enum::normalizeValue() for enum normalization logic.
Throws
InvalidArgumentException: if the class value is not in the allowed list.