Skip to content
PHP Ecosystem
Explore

AttributesInterface

API reference › HTML Contracts › Attribute › AttributesInterface

interfaceUIAwesome\Html\Contracts\Attribute\AttributesInterface
Sourcesrc/Attribute/AttributesInterface.php
Implemented by 4 types

Defines the public contract for objects that manage HTML attributes.

Provides an immutable API for adding, updating, reading, and removing HTML attributes on elements.

MethodDescriptionDefined by
addAttribute() abstractAdds or updates a single HTML attribute for the element.AttributesInterface
attributes() abstractAdds or updates the supplied HTML attributes, preserving all other attributes.AttributesInterface
class() abstractSets the class attribute.AttributesInterface
getAttribute() abstractReturns the value of a single HTML attribute.AttributesInterface
getAttributes() abstractReturns the array of HTML attributes for the element.AttributesInterface
removeAttribute() abstractRemoves a specific HTML attribute from the element.AttributesInterface
abstract public function addAttribute(string|UnitEnum $key, mixed $value): static

Adds or updates a single HTML attribute for the element.

Parameters

ParameterTypeDescription
$keystring|UnitEnumAttribute name.
$valuemixedAttribute value. Use null to remove the attribute.

Returns

static: New instance with the updated attribute.

abstract public function attributes(mixed[] $values): static

Adds or updates the supplied HTML attributes, preserving all other attributes.

Parameters

ParameterTypeDescription
$valuesmixed[]Associative array of attribute keys and values.

Returns

static: New instance with the updated attributes.

abstract public function class(string|Stringable|UnitEnum|null $value, bool $override = false): static

Sets the class attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullCSS class value, or null to remove the attribute.
$overrideboolWhether to override existing classes (true) or merge (false).

Returns

static: New instance with the updated class attribute.

abstract public function getAttribute(string|UnitEnum $key, mixed $default = null): mixed

Returns the value of a single HTML attribute.

Parameters

ParameterTypeDescription
$keystring|UnitEnumAttribute name.
$defaultmixedDefault value when the attribute is missing.

Returns

mixed: Attribute value or default.

abstract public function getAttributes(): mixed[]

Returns the array of HTML attributes for the element.

Returns

mixed[]: Attributes array assigned to the element.

abstract public function removeAttribute(string|UnitEnum $key): static

Removes a specific HTML attribute from the element.

Parameters

ParameterTypeDescription
$keystring|UnitEnumAttribute name to remove.

Returns

static: New instance without the specified attribute.