1 | <?php |
||
17 | class HtmlElement |
||
18 | { |
||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $tagName; |
||
23 | |||
24 | /** |
||
25 | * @var string[] |
||
26 | */ |
||
27 | protected $attributes = []; |
||
28 | |||
29 | /** |
||
30 | * @var HtmlElement|HtmlElement[]|string |
||
31 | */ |
||
32 | protected $contents; |
||
33 | |||
34 | /** |
||
35 | * @var bool |
||
36 | */ |
||
37 | protected $selfClosing = false; |
||
38 | |||
39 | /** |
||
40 | * @param string $tagName Name of the HTML tag |
||
41 | * @param string[] $attributes Array of attributes (values should be unescaped) |
||
42 | * @param HtmlElement|HtmlElement[]|string|null $contents Inner contents, pre-escaped if needed |
||
43 | * @param bool $selfClosing Whether the tag is self-closing |
||
44 | */ |
||
45 | 2544 | public function __construct(string $tagName, array $attributes = [], $contents = '', bool $selfClosing = false) |
|
53 | |||
54 | 102 | public function getTagName(): string |
|
58 | |||
59 | /** |
||
60 | * @return string[] |
||
61 | */ |
||
62 | 60 | public function getAllAttributes(): array |
|
66 | |||
67 | 69 | public function getAttribute(string $key): ?string |
|
75 | |||
76 | 21 | public function setAttribute(string $key, string $value): self |
|
82 | |||
83 | /** |
||
84 | * @param bool $asString |
||
85 | * |
||
86 | * @return HtmlElement|HtmlElement[]|string |
||
87 | */ |
||
88 | 93 | public function getContents(bool $asString = true) |
|
96 | |||
97 | /** |
||
98 | * Sets the inner contents of the tag (must be pre-escaped if needed) |
||
99 | * |
||
100 | * @param HtmlElement|HtmlElement[]|string $contents |
||
101 | * |
||
102 | * @return $this |
||
103 | */ |
||
104 | 2544 | public function setContents($contents): self |
|
110 | |||
111 | 2418 | public function __toString(): string |
|
131 | |||
132 | 2463 | private function getContentsAsString(): string |
|
144 | } |
||
145 |