Skip to content
PHP Ecosystem
Explore

BaseNaming

API reference › HTML Helper › Base › BaseNaming

abstract classUIAwesome\Html\Helper\Base\BaseNaming
Sourcesrc/Base/BaseNaming.php
1 subclass

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

MethodDescriptionDefined by
convertToPattern() staticConverts a regular expression literal to its pattern substring.BaseNaming
generateArrayableName() staticEnsure a form property name is arrayable (ends with []).BaseNaming
generateId() staticGenerate a unique identifier suitable for use as an HTML id attribute.BaseNaming
generateInputId() staticGenerate an input element id from a form model and property name.BaseNaming
generateInputName() staticGenerate a fully-qualified input name for form fields.BaseNaming
getShortNameClass() staticReturn the short class name, optionally formatted for ::class usage.BaseNaming
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

ParameterTypeDescription
$regexpstringRegular expression literal to convert (including delimiters and flags).
$delimiterstring|nullOptional 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.
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

ParameterTypeDescription
$namestringBase property name.

Returns

string: Arrayable property name.

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

ParameterTypeDescription
$prefixstringPrefix to prepend to the generated identifier.

Returns

string: Unique identifier string.

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

ParameterTypeDescription
$formModelstringForm model name (may be empty for non-tabular inputs).
$propertystringProperty name or complex property notation (for example items[0][name]).
$charsetstringCharacter set used by mb_strtolower (default: UTF-8).

Returns

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

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

ParameterTypeDescription
$formModelstringName of the form model (may be empty for simple inputs).
$propertystringProperty name or complex property notation.
$arrayableboolWhether to force the resulting name to be arrayable (append []).

Returns

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

Throws

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

ParameterTypeDescription
$classstringFully-qualified class name.
$suffixboolWhether to append ::class to the returned short name (default: true).
$lowercaseboolWhether to lowercase the class name before extracting the short name.

Returns

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