|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace RoyallTheFourth\HtmlDocument\Element; |
|
4
|
|
|
|
|
5
|
|
|
use RoyallTheFourth\HtmlDocument\Set\AttributeSet; |
|
6
|
|
|
use RoyallTheFourth\HtmlDocument\Set\ElementSet; |
|
7
|
|
|
use RoyallTheFourth\HtmlDocument\Tag\TagInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class AbstractElement |
|
11
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes |
|
12
|
|
|
*/ |
|
13
|
|
|
abstract class AbstractElement implements ElementInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var $attributes AttributeSet */ |
|
16
|
|
|
protected $attributes; |
|
17
|
|
|
/** @var $children ElementSet */ |
|
18
|
|
|
protected $children; |
|
19
|
|
|
/** @var $tag TagInterface */ |
|
20
|
|
|
protected $tag; |
|
21
|
|
|
|
|
22
|
|
|
final public function render(): string |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->tag->render(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey |
|
29
|
|
|
*/ |
|
30
|
|
|
public function withAccessKey(string $key): self |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->withAttribute('accesskey', $key); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class |
|
37
|
|
|
*/ |
|
38
|
|
|
public function withClass(string $class): self |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->withAttribute('class', $class); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable |
|
45
|
|
|
*/ |
|
46
|
|
|
public function withContentEditable(string $editable = 'true'): self |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->withAttribute('contenteditable', $editable); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contextmenu |
|
53
|
|
|
*/ |
|
54
|
|
|
public function withContextMenu(string $id): self |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->withAttribute('contextmenu', $id); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir |
|
61
|
|
|
*/ |
|
62
|
|
|
public function withDir(string $direction = 'auto'): self |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->withAttribute('dir', $direction); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden |
|
69
|
|
|
*/ |
|
70
|
|
|
public function withHidden(): self |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->withAttribute('hidden'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id |
|
77
|
|
|
*/ |
|
78
|
|
|
public function withId(string $id): self |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->withAttribute('id', $id); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang |
|
85
|
|
|
*/ |
|
86
|
|
|
public function withLang(string $lang): self |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->withAttribute('lang', $lang); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/style |
|
93
|
|
|
*/ |
|
94
|
|
|
public function withStyle(string $css): self |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->withAttribute('style', $css); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex |
|
101
|
|
|
*/ |
|
102
|
|
|
public function withTabIndex(int $tabIndex): self |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->withAttribute('tabindex', $tabIndex); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title |
|
109
|
|
|
*/ |
|
110
|
|
|
public function withTitle(string $title): self |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->withAttribute('title', $title); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/translate |
|
117
|
|
|
*/ |
|
118
|
|
|
public function withTranslate(string $translate = 'yes'): self |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->withAttribute('translate', $translate); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|