Skip to content
PHP Ecosystem
Explore

BaseAttributeBag

API reference › HTML Helper › Base › BaseAttributeBag

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

Provides reusable operations for associative HTML attribute bags.

MethodDescriptionDefined by
get() staticReturns an attribute value by key.BaseAttributeBag
normalizeKey() staticNormalizes an attribute key ensuring it has a specific prefix.BaseAttributeBag
remove() staticRemoves an attribute from the bag.BaseAttributeBag
replace() staticReplaces all attributes in the bag.BaseAttributeBag
set() staticSets a plain attribute key/value pair.BaseAttributeBag
setMany() staticSets multiple plain attributes.BaseAttributeBag
public static function get(mixed[] $attributes, string|UnitEnum $key, mixed $default = null, string $prefix = ''): mixed

Returns an attribute value by key.

Parameters

ParameterTypeDescription
$attributesmixed[]Attribute bag.
$keystring|UnitEnumAttribute key.
$defaultmixedDefault value when key is not present.
$prefixstringPrefix to ensure (for example, aria-, data-, on).

Returns

mixed: Attribute value or default.

Throws

public static function normalizeKey(mixed $key, string $prefix): string

Normalizes an attribute key ensuring it has a specific prefix.

Returns the key unchanged when it already has the prefix.

Parameters

ParameterTypeDescription
$keymixedKey to normalize. Accepts strings, Stringable objects, or UnitEnum cases.
$prefixstringPrefix to ensure (for example, aria-, data-, on).

Returns

string: Normalized key with the prefix ensured.

Throws

public static function remove(mixed[] &$attributes, string|UnitEnum $key, string $prefix = ''): void

Removes an attribute from the bag.

Parameters

ParameterTypeDescription
$attributesmixed[]Attribute bag to update in place.
$keystring|UnitEnumAttribute key.
$prefixstringPrefix to ensure (for example, aria-, data-, on).

Throws

public static function replace(mixed[] &$attributes, mixed[] $values, string $prefix = ''): void

Replaces all attributes in the bag.

Parameters

ParameterTypeDescription
$attributesmixed[]Attribute bag to replace in place.
$valuesmixed[]Values to set after clearing the bag.
$prefixstringPrefix to ensure (for example, aria-, data-, on).

Throws

public static function set(mixed[] &$attributes, string|UnitEnum $key, mixed $value, string $prefix = ''): void

Sets a plain attribute key/value pair.

Parameters

ParameterTypeDescription
$attributesmixed[]Attribute bag to update in place.
$keystring|UnitEnumAttribute key to normalize.
$valuemixedAttribute value. Use null to remove the attribute.
$prefixstringPrefix to ensure (for example, aria-, data-, on).

Throws

public static function setMany(mixed[] &$attributes, mixed[] $values, string $prefix = ''): void

Sets multiple plain attributes.

Parameters

ParameterTypeDescription
$attributesmixed[]Attribute bag to update in place.
$valuesmixed[]Values to set.
$prefixstringPrefix to ensure (for example, aria-, data-, on).

Throws