# BaseEnum

> Provides reusable normalization helpers for enum and scalar values.

[API reference](/docs/api/index.md) › [HTML Helper](/docs/extensions/html-helper/reference/index.md) › [Base](/docs/extensions/html-helper/reference/base/index.md) › BaseEnum

| abstract class | `UIAwesome\Html\Helper\Base\BaseEnum` |
| --- | --- |
| Source | [`src/Base/BaseEnum.php`](https://github.com/ui-awesome/html-helper/blob/main/src/Base/BaseEnum.php#L25) |

1 subclass:

- [`UIAwesome\Html\Helper\Enum`](/docs/extensions/html-helper/reference/enum/index.md)

Provides reusable normalization helpers for enum and scalar values.

[`BackedEnum`](https://www.php.net/manual/en/class.backedenum.php) for enums with scalar values.
[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) for all enum types.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`normalizeArray()`](#method-normalizeArray) static | Normalizes an array of enum values or mixed values to their scalar values or names. | `BaseEnum` |
| [`normalizeStringArray()`](#method-normalizeStringArray) static | Normalizes an array of enum values or mixed values to string representations. | `BaseEnum` |
| [`normalizeStringValue()`](#method-normalizeStringValue) static | Normalizes a single enum value or mixed value to a string representation. | `BaseEnum` |
| [`normalizeValue()`](#method-normalizeValue) static | Normalizes a single enum value to its scalar value or name. | `BaseEnum` |

## Method details

### normalizeArray() <span id="method-normalizeArray"></span>

```php
public static function normalizeArray(mixed[] $values): mixed[]
```

Normalizes an array of enum values or mixed values to their scalar values or names.

Applies [`normalizeValue()`](/docs/extensions/html-helper/reference/base/baseenum/index.md#method-normalizeValue) to each element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$values` | `mixed[]` | Array of enum instances or mixed values to normalize. |

**Returns**

`mixed[]`: Array of normalized scalar values, names, or original values for non-enums. [`normalizeValue()`](/docs/extensions/html-helper/reference/base/baseenum/index.md#method-normalizeValue) for single value normalization.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if any value is not an enum, scalar, array, or `null`.

### normalizeStringArray() <span id="method-normalizeStringArray"></span>

```php
public static function normalizeStringArray(mixed[] $values): string[]
```

Normalizes an array of enum values or mixed values to string representations.

Applies [`normalizeStringValue()`](/docs/extensions/html-helper/reference/base/baseenum/index.md#method-normalizeStringValue) to each element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$values` | `mixed[]` | Array of enum instances or mixed values to normalize. |

**Returns**

`string[]`: Array of normalized string representations. [`normalizeStringValue()`](/docs/extensions/html-helper/reference/base/baseenum/index.md#method-normalizeStringValue) for single value string normalization.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if any value is not an enum, scalar, array, or `null`.

### normalizeStringValue() <span id="method-normalizeStringValue"></span>

```php
public static function normalizeStringValue(mixed $value): string
```

Normalizes a single enum value or mixed value to a string representation.

Converts `null` to `null`, booleans to `true` or `false`, and arrays to `Array` for deterministic textual
output.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | Value to normalize. |

**Returns**

`string`: Normalized string representation. [`normalizeStringArray()`](/docs/extensions/html-helper/reference/base/baseenum/index.md#method-normalizeStringArray) for batch string normalization.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if the value is not an enum, scalar, array, or `null`.

### normalizeValue() <span id="method-normalizeValue"></span>

```php
public static function normalizeValue(mixed $value): ($value is UnitEnum ? int|string : ($value is string ? string : bool|float|int|mixed[]|null))
```

Normalizes a single enum value to its scalar value or name.

Returns the original value unchanged for non-enum input.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | Value to normalize. |

**Returns**

`($value is` [`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) `? int|string : ($value is string ? string : bool|float|int|mixed[]|null))`: Scalar value for BackedEnum, name for pure enums, or the original value for non-enums. [`normalizeArray()`](/docs/extensions/html-helper/reference/base/baseenum/index.md#method-normalizeArray) for batch normalization.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if the value is not an enum, scalar, array, or `null`.