ComponentContext
API reference › HTML Core › Config › ComponentContext
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.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$component readonly | string | Semantic component identifier, normalized to a string. | ComponentContext |
$metadata readonly | array<string, | Extensible semantic metadata available to config providers. | ComponentContext |
$scheme readonly | string| | Optional color scheme, normalized to a string. | ComponentContext |
$size readonly | string| | Optional component size, normalized to a string. | ComponentContext |
$states readonly | list<string> | Active component states, normalized to strings. | ComponentContext |
$variant readonly | string| | Optional presentation variant, normalized to a string. | ComponentContext |
Methods
Section titled “Methods”| Method | Description | Defined 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 |
Property details
Section titled “Property details”$metadata
Section titled “$metadata ”public readonly array<string, mixed> $metadataExtensible semantic metadata available to config providers.
Object values are stored by reference, so pass immutable values when deep immutability is required.
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”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
| Parameter | Type | Description |
|---|---|---|
$component | BackedEnum| | Semantic component identifier, for example field.control.email. |
$variant | BackedEnum| | Optional presentation variant. |
$size | BackedEnum| | Optional component size. |
$scheme | BackedEnum| | Optional color scheme. |
$states | array<array-key, | Active component states, as strings or string-backed enums. |
$metadata | array<array-key, | 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.
get()
Section titled “get() ”public function get(string $key, mixed $default = null): mixedReturns semantic metadata or the provided default value.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | Metadata key to look up. |
$default | mixed | Value returned when the key is missing. |
Returns
mixed: Stored metadata value, or the default when the key is missing.
hasState()
Section titled “hasState() ”public function hasState(BackedEnum|string $state): boolWhether the component has the specified state.
Parameters
| Parameter | Type | Description |
|---|---|---|
$state | BackedEnum| | State name, or a string-backed enum whose backing value is the state name. |
Returns
bool: true if the state is active, false otherwise.
Throws
InvalidArgumentException: If the state is an int-backed enum.