1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebTheory\Html; |
4
|
|
|
|
5
|
|
|
use WebTheory\Html\Traits\ElementConstructorTrait; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @method static string div(string $inner = '', array $attributes = []) |
9
|
|
|
* @method static string span(string $inner = '', array $attributes = []) |
10
|
|
|
* @method static string main(string $inner = '', array $attributes = []) |
11
|
|
|
* @method static string form(string $inner = '', array $attributes = []) |
12
|
|
|
* @method static string h1(string $inner = '', array $attributes = []) |
13
|
|
|
* @method static string h2(string $inner = '', array $attributes = []) |
14
|
|
|
* @method static string h3(string $inner = '', array $attributes = []) |
15
|
|
|
* @method static string h4(string $inner = '', array $attributes = []) |
16
|
|
|
* @method static string h5(string $inner = '', array $attributes = []) |
17
|
|
|
* @method static string h6(string $inner = '', array $attributes = []) |
18
|
|
|
* @method static string input(array $attributes = []) |
19
|
|
|
*/ |
20
|
|
|
class Html |
21
|
|
|
{ |
22
|
|
|
use ElementConstructorTrait { |
23
|
|
|
tag as public; |
24
|
|
|
open as public; |
25
|
|
|
close as public; |
26
|
|
|
maybeClose as public; |
27
|
|
|
tagIsVoid as public; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public static function __callStatic(string $tag, array $args): string |
31
|
|
|
{ |
32
|
|
|
if (static::tagIsVoid($tag)) { |
33
|
|
|
$attributes = $args[0] ?? []; |
34
|
|
|
$html = static::tag($tag, $attributes); |
35
|
|
|
} else { |
36
|
|
|
$inner = $args[0] ?? ''; |
37
|
|
|
$attributes = $args[1] ?? []; |
38
|
|
|
$html = static::tag($tag, $attributes, $inner); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $html; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public static function attributes(array $attributes, bool $trim = true): string |
45
|
|
|
{ |
46
|
|
|
$attributes = static::parseAttributes($attributes); |
47
|
|
|
|
48
|
|
|
return $trim ? ltrim($attributes) : $attributes; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|