BaseNaming
API reference › HTML Helper › Base › BaseNaming
1 subclass
Provides reusable helpers for form names, element IDs, and pattern extraction.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
convertToPattern() static | Converts a regular expression literal to its pattern substring. | BaseNaming |
generateArrayableName() static | Ensure a form property name is arrayable (ends with []). | BaseNaming |
generateId() static | Generate a unique identifier suitable for use as an HTML id attribute. | BaseNaming |
generateInputId() static | Generate an input element id from a form model and property name. | BaseNaming |
generateInputName() static | Generate a fully-qualified input name for form fields. | BaseNaming |
getShortNameClass() static | Return the short class name, optionally formatted for ::class usage. | BaseNaming |
Method details
Section titled “Method details”convertToPattern()
Section titled “convertToPattern() ”public static function convertToPattern(string $regexp, string|null $delimiter = null): stringConverts 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| | 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: 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()
Section titled “generateArrayableName() ”public static function generateArrayableName(string $name): stringEnsure 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()
Section titled “generateId() ”public static function generateId(string $prefix = 'id-'): stringGenerate 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()
Section titled “generateInputId() ”public static function generateInputId(string $formModel = '', string $property = '', string $charset = 'UTF-8'): stringGenerate 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()
Section titled “generateInputName() ”public static function generateInputName(string $formModel, string $property, bool $arrayable = false): stringGenerate 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: if a tabular input is requested and the form model name is empty.
getShortNameClass()
Section titled “getShortNameClass() ”public static function getShortNameClass(string $class, bool $suffix = true, bool $lowercase = false): stringReturn 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.