Skip to content
PHP Ecosystem
Explore

ComponentContext

API reference › HTML Core › Config › ComponentContext

final readonly classUIAwesome\Html\Core\Config\ComponentContext
Sourcesrc/Config/ComponentContext.php

Describes the semantic component and qualifiers used to resolve config recipes.

The component identifier, qualifiers, and states accept a string or a string-backed enum. Enum cases are normalized to their backing values, so the public properties and ComponentContext::hasState() always work with plain strings, regardless of how the context was created.

PropertyTypeDescriptionDefined by
$component readonlystringSemantic component identifier, normalized to a string.ComponentContext
$metadata readonlyarray<string, mixed>Extensible semantic metadata available to config providers.ComponentContext
$scheme readonlystring|nullOptional color scheme, normalized to a string.ComponentContext
$size readonlystring|nullOptional component size, normalized to a string.ComponentContext
$states readonlylist<string>Active component states, normalized to strings.ComponentContext
$variant readonlystring|nullOptional presentation variant, normalized to a string.ComponentContext
MethodDescriptionDefined by
__construct()Creates a semantic component context.ComponentContext
get()Returns semantic metadata or the provided default value.ComponentContext
hasState()Whether the component has the specified state.ComponentContext
public readonly array<string, mixed> $metadata

Extensible semantic metadata available to config providers.

Object values are stored by reference, so pass immutable values when deep immutability is required.

public function __construct(BackedEnum|string $component, BackedEnum|string|null $variant = null, BackedEnum|string|null $size = null, BackedEnum|string|null $scheme = null, array<array-key, mixed> $states = [], array<array-key, mixed> $metadata = [])

Creates a semantic component context.

Parameters

ParameterTypeDescription
$componentBackedEnum|stringSemantic component identifier, for example field.control.email.
$variantBackedEnum|string|nullOptional presentation variant.
$sizeBackedEnum|string|nullOptional component size.
$schemeBackedEnum|string|nullOptional color scheme.
$statesarray<array-key, mixed>Active component states, as strings or string-backed enums.
$metadataarray<array-key, mixed>Additional semantic metadata.

Throws

  • InvalidArgumentException: If the component identifier, a qualifier, or a state is an int-backed enum, is empty, or contains whitespace, the states are not a list of strings or backed enums, or a metadata key is not a non-empty string.
public function get(string $key, mixed $default = null): mixed

Returns semantic metadata or the provided default value.

Parameters

ParameterTypeDescription
$keystringMetadata key to look up.
$defaultmixedValue returned when the key is missing.

Returns

mixed: Stored metadata value, or the default when the key is missing.

public function hasState(BackedEnum|string $state): bool

Whether the component has the specified state.

Parameters

ParameterTypeDescription
$stateBackedEnum|stringState name, or a string-backed enum whose backing value is the state name.

Returns

bool: true if the state is active, false otherwise.

Throws