Repository navigation
Expand file tree
/
Copy pathEmptyElement.php
More file actions
79 lines (68 loc) · 2.21 KB
/
Copy pathEmptyElement.php
File metadata and controls
79 lines (68 loc) · 2.21 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
declare(strict_types=1);
namespace Eightfold\HtmlBuilder;
use Eightfold\HtmlBuilder\PropertyInterface;
use Eightfold\HtmlBuilder\Element;
use Stringable;
/**
* Magic static void-element factories. Generated from the WHATWG HTML
* living standard (https://html.spec.whatwg.org/, retrieved 2026-11-10):
* 13 void elements, derived from each element's "Tag omission in
* text/html: No end tag." entry. Alphabetical.
*
* @method static static area(string ...$properties)
* @method static static base(string ...$properties)
* @method static static br(string ...$properties)
* @method static static col(string ...$properties)
* @method static static embed(string ...$properties)
* @method static static hr(string ...$properties)
* @method static static img(string ...$properties)
* @method static static input(string ...$properties)
* @method static static link(string ...$properties)
* @method static static meta(string ...$properties)
* @method static static source(string ...$properties)
* @method static static track(string ...$properties)
* @method static static wbr(string ...$properties)
*/
class EmptyElement implements PropertyInterface
{
public static function create(string $name, string ...$properties): static
{
$properties = array_values($properties);
return new static($name, $properties);
}
/**
* @param list<string> $properties
*/
public static function __callStatic(string $name, array $properties = []): static
{
return new static($name, $properties);
}
/**
* @param list<string> $properties
*/
final private function __construct(
private string $name,
private array $properties = [],
) {
}
public function props(string ...$properties): static
{
$this->properties = array_values($properties);
return $this;
}
public function prop(string $prop): static
{
$this->properties[] = $prop;
return $this;
}
public function toString(): string
{
return (string) Element::create($this->name)->omitEndTag()
->props(...$this->properties);
}
public function __toString(): string
{
return $this->toString();
}
}