|
15 | 15 | use function strrchr; |
16 | 16 | use function strrpos; |
17 | 17 | use function substr; |
| 18 | +use function uniqid; |
18 | 19 |
|
19 | 20 | /** |
20 | 21 | * Utils provides a set of static methods for common tasks. |
@@ -65,23 +66,25 @@ public static function convertToPattern(string $regexp, string $delimiter = null |
65 | 66 | } |
66 | 67 |
|
67 | 68 | /** |
68 | | - * Returns the short name of the given class. |
| 69 | + * Generate arrayable name from string. |
69 | 70 | * |
70 | | - * @param string $class The class name. |
| 71 | + * @param string $name String to convert. |
71 | 72 | */ |
72 | | - public static function getShortNameClass(string $class): string |
| 73 | + public static function generateArrayableName(string $name): string |
73 | 74 | { |
74 | | - return substr(strrchr($class, '\\'), 1) . '::class'; |
| 75 | + return !str_ends_with($name, '[]') ? $name . '[]' : $name; |
75 | 76 | } |
76 | 77 |
|
77 | 78 | /** |
78 | | - * Generate arrayable name from string. |
| 79 | + * Generates a unique ID for an element. |
79 | 80 | * |
80 | | - * @param string $name String to convert. |
| 81 | + * @param string $prefix The prefix string. If not specified, the default is 'id-'. |
| 82 | + * |
| 83 | + * @return string The unique ID. |
81 | 84 | */ |
82 | | - public static function generateArrayableName(string $name): string |
| 85 | + public static function generateId(string $prefix = 'id-'): string |
83 | 86 | { |
84 | | - return !str_ends_with($name, '[]') ? $name . '[]' : $name; |
| 87 | + return uniqid($prefix); |
85 | 88 | } |
86 | 89 |
|
87 | 90 | /** |
@@ -148,6 +151,16 @@ public static function generateInputName(string $fieldModel, string $property, b |
148 | 151 | throw new InvalidArgumentException('The field model cannot be empty for tabular inputs.'); |
149 | 152 | } |
150 | 153 |
|
| 154 | + /** |
| 155 | + * Returns the short name of the given class. |
| 156 | + * |
| 157 | + * @param string $class The class name. |
| 158 | + */ |
| 159 | + public static function getShortNameClass(string $class): string |
| 160 | + { |
| 161 | + return substr(strrchr($class, '\\'), 1) . '::class'; |
| 162 | + } |
| 163 | + |
151 | 164 | /** |
152 | 165 | * This method parses an property expression and returns an associative array containing real property name, |
153 | 166 | * prefix, and suffix. |
|
0 commit comments