generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHasAttributes.php
43 lines (36 loc) · 987 Bytes
/
HasAttributes.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
42
43
<?php
declare(strict_types=1);
namespace UIAwesome\Html\Concern;
use function array_merge;
/**
* Is used by widgets which implement the attribute method.
*
* @link https://www.w3.org/TR/html52/dom.html#global-attributes
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
*/
trait HasAttributes
{
protected array $attributes = [];
/**
* Set the `HTML` attributes.
*
* @param array $values Attribute values indexed by attribute names.
*
* @return static A new instance of the current class with the specified attributes.
*/
public function attributes(array $values): static
{
$new = clone $this;
$new->attributes = array_merge($this->attributes, $values);
return $new;
}
/**
* Get the `HTML` attributes.
*
* @return array Attribute values indexed by attribute names.
*/
public function getAttributes(): array
{
return $this->attributes;
}
}