1 | <?php |
||
12 | class Element |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $name; |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $value; |
||
22 | /** |
||
23 | * @var Attribute[] |
||
24 | */ |
||
25 | private $attributes = []; |
||
26 | |||
27 | /** |
||
28 | * Element constructor. |
||
29 | * |
||
30 | * @param string $name |
||
31 | * @param string|null $value |
||
32 | */ |
||
33 | public function __construct(string $name, string $value = null) |
||
34 | 16 | { |
|
35 | $this->name = $name; |
||
36 | 16 | ||
37 | $this->setValue($value ?? ''); |
||
38 | 16 | } |
|
39 | 16 | ||
40 | /** |
||
41 | 16 | * @return string |
|
42 | */ |
||
43 | final public function getName(): string |
||
44 | { |
||
45 | return $this->name; |
||
46 | 16 | } |
|
47 | |||
48 | 16 | /** |
|
49 | * @param string $value |
||
50 | */ |
||
51 | final public function setValue(string $value) |
||
52 | { |
||
53 | $value = trim($value); |
||
|
|||
54 | 16 | if (strlen($value) !== 0) { |
|
55 | $this->value = $value; |
||
56 | 16 | } |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return bool |
||
61 | */ |
||
62 | 16 | final public function hasValue(): bool |
|
63 | { |
||
64 | 16 | return $this->value !== null; |
|
65 | 16 | } |
|
66 | 14 | ||
67 | /** |
||
68 | 16 | * @return string |
|
69 | */ |
||
70 | final public function getValue(): string |
||
74 | |||
75 | 14 | /** |
|
76 | * @param Attribute $attribute |
||
77 | */ |
||
78 | final public function setAttribute(Attribute $attribute) |
||
82 | |||
83 | 12 | /** |
|
84 | 12 | * @return bool |
|
85 | */ |
||
86 | final public function hasAttributes(): bool |
||
90 | |||
91 | 3 | /** |
|
92 | * @return Attribute[] |
||
93 | */ |
||
94 | final public function getAttributes(): array |
||
98 | |||
99 | 16 | /** |
|
100 | * @param ElementVisitorInterface $visitor |
||
101 | */ |
||
102 | public function accept(ElementVisitorInterface $visitor) |
||
106 | } |