# BaseNaming

> Provides reusable helpers for form names, element IDs, and pattern extraction.

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

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

1 subclass:

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

Provides reusable helpers for form names, element IDs, and pattern extraction.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`convertToPattern()`](#method-convertToPattern) static | Converts a regular expression literal to its pattern substring. | `BaseNaming` |
| [`generateArrayableName()`](#method-generateArrayableName) static | Ensure a form property name is arrayable (ends with `[]`). | `BaseNaming` |
| [`generateId()`](#method-generateId) static | Generate a unique identifier suitable for use as an HTML `id` attribute. | `BaseNaming` |
| [`generateInputId()`](#method-generateInputId) static | Generate an input element id from a form model and property name. | `BaseNaming` |
| [`generateInputName()`](#method-generateInputName) static | Generate a fully-qualified input name for form fields. | `BaseNaming` |
| [`getShortNameClass()`](#method-getShortNameClass) static | Return the short class name, optionally formatted for `::class` usage. | `BaseNaming` |

## Method details

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

```php
public static function convertToPattern(string $regexp, string|null $delimiter = null): string
```

Converts a regular expression literal to its pattern substring.

Extracts the pattern portion from a regular expression literal, converting `\\x{...}` hex escapes to `\u`
notation. The optional delimiter may be inferred from the literal when not provided.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$regexp` | `string` | Regular expression literal to convert (including delimiters and flags). |
| `$delimiter` | `string\|null` | Optional delimiter character. If `null`, the delimiter is inferred from the provided literal when possible. |

**Returns**

`string`: Pattern substring extracted from the regular expression literal.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if the delimiter is not provided and cannot be inferred, if the literal is too short to contain a pattern, or if the regular expression is malformed.

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

```php
public static function generateArrayableName(string $name): string
```

Ensure a form property name is arrayable (ends with `[]`).

Returns the original name if it already ends with `[]`, otherwise appends `[]` to make it arrayable for tabular
or multiple-value inputs.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Base property name. |

**Returns**

`string`: Arrayable property name.

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

```php
public static function generateId(string $prefix = 'id-'): string
```

Generate a unique identifier suitable for use as an HTML `id` attribute.

Uses a lightweight unique prefixing strategy appropriate for template generation and helper utilities.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$prefix` | `string` | Prefix to prepend to the generated identifier. |

**Returns**

`string`: Unique identifier string.

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

```php
public static function generateInputId(string $formModel = '', string $property = '', string $charset = 'UTF-8'): string
```

Generate an input element id from a form model and property name.

Produces a deterministic id by lowercasing the generated input name and replacing array and bracket characters
with hyphens, ensuring the result is suitable for use as an HTML `id` attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$formModel` | `string` | Form model name (may be empty for non-tabular inputs). |
| `$property` | `string` | Property name or complex property notation (for example `items[0][name]`). |
| `$charset` | `string` | Character set used by `mb_strtolower` (default: `UTF-8`). |

**Returns**

`string`: Generated id string safe for use in HTML attributes.

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

```php
public static function generateInputName(string $formModel, string $property, bool $arrayable = false): string
```

Generate a fully-qualified input name for form fields.

Builds a form input `name` value from a form model and a property. Supports arrayable properties and tabular
inputs by parsing property prefixes and suffixes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$formModel` | `string` | Name of the form model (may be empty for simple inputs). |
| `$property` | `string` | Property name or complex property notation. |
| `$arrayable` | `bool` | Whether to force the resulting name to be arrayable (append `[]`). |

**Returns**

`string`: Generated input name suitable for use in HTML form `name` attributes.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if a tabular input is requested and the form model name is empty.

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

```php
public static function getShortNameClass(string $class, bool $suffix = true, bool $lowercase = false): string
```

Return the short class name, optionally formatted for `::class` usage.

Extracts the short portion of a fully-qualified class name and optionally returns it as a class constant
reference (`ShortName::class`). Optionally lowercases the input before extraction.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$class` | `string` | Fully-qualified class name. |
| `$suffix` | `bool` | Whether to append `::class` to the returned short name (default: `true`). |
| `$lowercase` | `bool` | Whether to lowercase the class name before extracting the short name. |

**Returns**

`string`: Short class name or `ShortName::class` when `$suffix` is `true`.