Skip to content
PHP Ecosystem
Explore

BaseCSSClass

API reference › HTML Helper › Base › BaseCSSClass

abstract classUIAwesome\Html\Helper\Base\BaseCSSClass
Sourcesrc/Base/BaseCSSClass.php
1 subclass

Provides reusable normalization and validation for HTML class attributes.

MethodDescriptionDefined by
add() staticAdds one or more CSS classes to an attribute array with validation and merging logic.BaseCSSClass
render() staticRenders a validated CSS class name using a base format and an allowed value list.BaseCSSClass
public static function add(mixed[] &$attributes, mixed[]|string|Stringable|UnitEnum|null $classes, bool $override = false): void

Adds 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

ParameterTypeDescription
$attributesmixed[]Attribute array to modify. Passed by reference and updated in place.
$classesmixed[]|string|Stringable|UnitEnum|nullClasses to add.
$overrideboolWhether to override (true) or merge (false, default) with existing classes.
public static function render(string|UnitEnum $class, string $baseClass, list<scalar|UnitEnum|null> $allowed): string

Renders 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

ParameterTypeDescription
$classstring|UnitEnumClass value to validate and render.
$baseClassstringBase class format string (for example, btn-%s).
$allowedlist<scalar|UnitEnum|null>List of allowed class values for validation.

Returns

string: Formatted and validated CSS class name. Enum::normalizeValue() for enum normalization logic.

Throws