|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BestServedCold\HTMLBuilder; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Tag |
|
7
|
|
|
* |
|
8
|
|
|
* @package BestServedCold\Benchmark\Output\Html |
|
9
|
|
|
* @method static $this a |
|
10
|
|
|
* @method static $this abbr |
|
11
|
|
|
* @method static $this address |
|
12
|
|
|
* @method static $this area |
|
13
|
|
|
* @method static $this article |
|
14
|
|
|
* @method static $this aside |
|
15
|
|
|
* @method static $this audio |
|
16
|
|
|
* @method static $this b |
|
17
|
|
|
* @method static $this base |
|
18
|
|
|
* @method static $this bdi |
|
19
|
|
|
* @method static $this bdo |
|
20
|
|
|
* @method static $this blockquote |
|
21
|
|
|
* @method static $this body |
|
22
|
|
|
* @method static $this br |
|
23
|
|
|
* @method static $this button |
|
24
|
|
|
* @method static $this canvas |
|
25
|
|
|
* @method static $this caption |
|
26
|
|
|
* @method static $this cite |
|
27
|
|
|
* @method statid $this code |
|
28
|
|
|
* @method static $this col |
|
29
|
|
|
* @method static $this colgroup |
|
30
|
|
|
* @method static $this datalist |
|
31
|
|
|
* @method static $this dd |
|
32
|
|
|
* @method static $this del |
|
33
|
|
|
* @method static $this details |
|
34
|
|
|
* @method static $this dfn |
|
35
|
|
|
* @method static $this dialog |
|
36
|
|
|
* @method static $this div |
|
37
|
|
|
* @method static $this dl |
|
38
|
|
|
* @method static $this dt |
|
39
|
|
|
* @method static $this em |
|
40
|
|
|
* @method static $this embed |
|
41
|
|
|
* @method static $this fieldset |
|
42
|
|
|
* @method static $this figcaption |
|
43
|
|
|
* @method static $this figure |
|
44
|
|
|
* @method static $this footer |
|
45
|
|
|
* @method static $this form |
|
46
|
|
|
* @method static $this h1 |
|
47
|
|
|
* @method static $this h2 |
|
48
|
|
|
* @method static $this h3 |
|
49
|
|
|
* @method static $this h4 |
|
50
|
|
|
* @method static $this h5 |
|
51
|
|
|
* @method static $this h6 |
|
52
|
|
|
* @method static $this head |
|
53
|
|
|
* @method static $this header |
|
54
|
|
|
* @method static $this hr |
|
55
|
|
|
* @method static $this html |
|
56
|
|
|
* @method static $this i |
|
57
|
|
|
* @method static $this iframe |
|
58
|
|
|
* @method static $this img |
|
59
|
|
|
* @method static $this input |
|
60
|
|
|
* @method static $this ins |
|
61
|
|
|
* @method static $this kbd |
|
62
|
|
|
* @method static $this keygen |
|
63
|
|
|
* @method static $this label |
|
64
|
|
|
* @method static $this legend |
|
65
|
|
|
* @method static $this li |
|
66
|
|
|
* @method static $this link |
|
67
|
|
|
* @method static $this main |
|
68
|
|
|
* @method static $this map |
|
69
|
|
|
* @method static $this mark |
|
70
|
|
|
* @method static $this menu |
|
71
|
|
|
* @method static $this menuitem |
|
72
|
|
|
* @method static $this meta |
|
73
|
|
|
* @method static $this meter |
|
74
|
|
|
*
@method static $this nav |
|
75
|
|
|
*
@method static $this noscript |
|
76
|
|
|
*
@method static $this object |
|
77
|
|
|
*
@method static $this ol |
|
78
|
|
|
* @method static $this optgroup |
|
79
|
|
|
*
@method static $this option |
|
80
|
|
|
*
@method static $this output |
|
81
|
|
|
*
@method static $this p |
|
82
|
|
|
*
@method static $this param |
|
83
|
|
|
*
@method static $this picture |
|
84
|
|
|
* @method static $this pre |
|
85
|
|
|
*
@method static $this progress |
|
86
|
|
|
*
@method static $this q |
|
87
|
|
|
*
@method static $this rp |
|
88
|
|
|
*
@method static $this rt |
|
89
|
|
|
*
@method static $this ruby |
|
90
|
|
|
*
@method static $this s |
|
91
|
|
|
*
@method static $this samp |
|
92
|
|
|
*
@method static $this script |
|
93
|
|
|
* @method static $this section |
|
94
|
|
|
*
@method static $this select |
|
95
|
|
|
* @method static $this small |
|
96
|
|
|
* @method static $this source |
|
97
|
|
|
*
@method static $this span |
|
98
|
|
|
* @method static $this strong |
|
99
|
|
|
*
@method static $this style |
|
100
|
|
|
* @method static $this sub |
|
101
|
|
|
* @method static $this summary |
|
102
|
|
|
* @method static $this sup |
|
103
|
|
|
* @method static $this table |
|
104
|
|
|
* @method static $this tbody |
|
105
|
|
|
* @method static $this td |
|
106
|
|
|
* @method static $this textarea |
|
107
|
|
|
*
@method static $this tfoot |
|
108
|
|
|
* @method static $this th |
|
109
|
|
|
* @method static $this thead |
|
110
|
|
|
*
@method static $this time |
|
111
|
|
|
* @method static $this title |
|
112
|
|
|
* @method static $this tr |
|
113
|
|
|
* @method static $this track |
|
114
|
|
|
* @method static $this u |
|
115
|
|
|
*
@method static $this ul |
|
116
|
|
|
*
@method static $this var |
|
117
|
|
|
* @method static $this video |
|
118
|
|
|
*
@method static $this wbr |
|
119
|
|
|
* @method static $this |
|
120
|
|
|
*/ |
|
121
|
|
|
class Builder extends Element |
|
122
|
|
|
{ |
|
123
|
|
|
/** |
|
124
|
|
|
* @var array |
|
125
|
|
|
*/ |
|
126
|
|
|
private static $elements = [ |
|
127
|
|
|
'a', |
|
128
|
|
|
'abbr', |
|
129
|
|
|
'address', |
|
130
|
|
|
'area', |
|
131
|
|
|
'article', |
|
132
|
|
|
'aside', |
|
133
|
|
|
'audio', |
|
134
|
|
|
'b', |
|
135
|
|
|
'base', |
|
136
|
|
|
'bdi', |
|
137
|
|
|
'bdo', |
|
138
|
|
|
'blockquote', |
|
139
|
|
|
'body', |
|
140
|
|
|
'br', |
|
141
|
|
|
'button', |
|
142
|
|
|
'canvas', |
|
143
|
|
|
'caption', |
|
144
|
|
|
'cite', |
|
145
|
|
|
'code', |
|
146
|
|
|
'col', |
|
147
|
|
|
'colgroup', |
|
148
|
|
|
'datalist', |
|
149
|
|
|
'dd', |
|
150
|
|
|
'del', |
|
151
|
|
|
'details', |
|
152
|
|
|
'dfn', |
|
153
|
|
|
'dialog', |
|
154
|
|
|
'div', |
|
155
|
|
|
'dl', |
|
156
|
|
|
'dt', |
|
157
|
|
|
'em', |
|
158
|
|
|
'embed', |
|
159
|
|
|
'fieldset', |
|
160
|
|
|
'figcaption', |
|
161
|
|
|
'figure', |
|
162
|
|
|
'footer', |
|
163
|
|
|
'form', |
|
164
|
|
|
'h1', |
|
165
|
|
|
'h2', |
|
166
|
|
|
'h3', |
|
167
|
|
|
'h4', |
|
168
|
|
|
'h5', |
|
169
|
|
|
'h6', |
|
170
|
|
|
'head', |
|
171
|
|
|
'header', |
|
172
|
|
|
'hr', |
|
173
|
|
|
'html', |
|
174
|
|
|
'i', |
|
175
|
|
|
'iframe', |
|
176
|
|
|
'img', |
|
177
|
|
|
'input', |
|
178
|
|
|
'ins', |
|
179
|
|
|
'kbd', |
|
180
|
|
|
'keygen', |
|
181
|
|
|
'label', |
|
182
|
|
|
'legend', |
|
183
|
|
|
'li', |
|
184
|
|
|
'link', |
|
185
|
|
|
'main', |
|
186
|
|
|
'map', |
|
187
|
|
|
'mark', |
|
188
|
|
|
'menu', |
|
189
|
|
|
'menuitem', |
|
190
|
|
|
'meta', |
|
191
|
|
|
'meter', |
|
192
|
|
|
'nav', |
|
193
|
|
|
'noscript', |
|
194
|
|
|
'object', |
|
195
|
|
|
'ol', |
|
196
|
|
|
'optgroup', |
|
197
|
|
|
'option', |
|
198
|
|
|
'output', |
|
199
|
|
|
'p', |
|
200
|
|
|
'param', |
|
201
|
|
|
'picture', |
|
202
|
|
|
'pre', |
|
203
|
|
|
'progress', |
|
204
|
|
|
'q', |
|
205
|
|
|
'rp', |
|
206
|
|
|
'rt', |
|
207
|
|
|
'ruby', |
|
208
|
|
|
's', |
|
209
|
|
|
'samp', |
|
210
|
|
|
'script', |
|
211
|
|
|
'section', |
|
212
|
|
|
'select', |
|
213
|
|
|
'small', |
|
214
|
|
|
'source', |
|
215
|
|
|
'span', |
|
216
|
|
|
'strong', |
|
217
|
|
|
'style', |
|
218
|
|
|
'sub', |
|
219
|
|
|
'summary', |
|
220
|
|
|
'sup', |
|
221
|
|
|
'table', |
|
222
|
|
|
'tbody', |
|
223
|
|
|
'td', |
|
224
|
|
|
'textarea', |
|
225
|
|
|
'tfoot', |
|
226
|
|
|
'th', |
|
227
|
|
|
'thead', |
|
228
|
|
|
'time', |
|
229
|
|
|
'title', |
|
230
|
|
|
'tr', |
|
231
|
|
|
'track', |
|
232
|
|
|
'u', |
|
233
|
|
|
'ul', |
|
234
|
|
|
'var', |
|
235
|
|
|
'video', |
|
236
|
|
|
'wbr' |
|
237
|
|
|
]; |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* @var array |
|
241
|
|
|
*/ |
|
242
|
|
|
private static $void = [ |
|
|
|
|
|
|
243
|
|
|
'area', |
|
244
|
|
|
'base', |
|
245
|
|
|
'br', |
|
246
|
|
|
'col', |
|
247
|
|
|
'command', |
|
248
|
|
|
'embed', |
|
249
|
|
|
'hr', |
|
250
|
|
|
'img', |
|
251
|
|
|
'input', |
|
252
|
|
|
'keygen', |
|
253
|
|
|
'link', |
|
254
|
|
|
'meta', |
|
255
|
|
|
'param', |
|
256
|
|
|
'source', |
|
257
|
|
|
'track', |
|
258
|
|
|
'wbr' |
|
259
|
|
|
]; |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* @param $name |
|
263
|
|
|
* @param $arguments |
|
264
|
|
|
* @throws \Exception |
|
265
|
|
|
* @return Element |
|
266
|
|
|
*/ |
|
267
|
2 |
|
public static function __callStatic($name, $arguments) |
|
268
|
|
|
{ |
|
269
|
2 |
|
if (in_array($name, self::$elements)) { |
|
270
|
2 |
|
return self::voidTag($name) ? Element::add($name)->void() : Element::add($name); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
1 |
|
throw new \Exception('Method [' . $name . '] does not exist in context [' . static::class . '].'); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* @param null $value |
|
278
|
|
|
* @return Element |
|
279
|
|
|
*/ |
|
280
|
1 |
|
public static function comment($value = null) |
|
281
|
|
|
{ |
|
282
|
1 |
|
return (new Element('!--' . $value . '--'))->void(); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* @param null $value |
|
287
|
|
|
* @return Element |
|
288
|
|
|
*/ |
|
289
|
1 |
|
public static function doctype($value = null) |
|
290
|
|
|
{ |
|
291
|
1 |
|
return (new Element('!DOCTYPE'))->attribute($value = $value ?: 'html')->void(); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* @param $name |
|
296
|
|
|
* @return bool |
|
297
|
|
|
*/ |
|
298
|
2 |
|
private static function voidTag($name) |
|
299
|
|
|
{ |
|
300
|
2 |
|
return in_array($name, self::$void); |
|
301
|
|
|
} |
|
302
|
|
|
} |
|
303
|
|
|
|