generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHasName.php
41 lines (34 loc) · 978 Bytes
/
HasName.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace UIAwesome\Html\Attribute;
/**
* Is used by widgets that implement the name method.
*/
trait HasName
{
/**
* Set the name part of the name/value pair associated with this element for the purposes of form submission.
*
* @param string|null $value The name of the widget.
*
* @return static A new instance of the current class with the specified name.
*
* @link https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-name
*/
public function name(string|null $value): static
{
if ($value === '') {
return $this;
}
$new = clone $this;
$new->attributes['name'] = $value;
return $new;
}
public function getName(): string
{
if (isset($this->attributes['name']) && is_string($this->attributes['name'])) {
return $this->attributes['name'];
}
return '';
}
}