-
Notifications
You must be signed in to change notification settings - Fork 22
/
Tag.php
105 lines (84 loc) · 2.24 KB
/
Tag.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Pentatrion\ViteBundle\Model;
class Tag
{
public const SCRIPT_TAG = 'script';
public const LINK_TAG = 'link';
/**
* @param array<string, bool|string|null> $attributes
*/
public function __construct(
private string $tagName,
private array $attributes = [],
private string $content = '',
private bool $internal = false
) {
}
public function getTagName(): string
{
return $this->tagName;
}
public function isScriptTag(): bool
{
return self::SCRIPT_TAG === $this->tagName;
}
public function isLinkTag(): bool
{
return self::LINK_TAG === $this->tagName;
}
public function isStylesheet(): bool
{
return self::LINK_TAG === $this->tagName && 'stylesheet' === $this->getAttribute('rel');
}
public function isModulePreload(): bool
{
return self::LINK_TAG === $this->tagName && 'modulepreload' === $this->getAttribute('rel');
}
public function isModule(): bool
{
return self::SCRIPT_TAG === $this->tagName && 'module' === $this->getAttribute('type');
}
/**
* @return array<string, bool|string|null>
*/
public function getAttributes(): array
{
return $this->attributes;
}
public function getAttribute(string $key): string|bool|null
{
return $this->attributes[$key] ?? null;
}
/**
* @param string $name The attribute name
* @param string|bool $value Value can be "true" to have an attribute without a value (e.g. "defer")
*/
public function setAttribute(string $name, string|bool $value): self
{
$this->attributes[$name] = $value;
return $this;
}
public function removeAttribute(string $name): self
{
unset($this->attributes[$name]);
return $this;
}
public function getContent(): string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function removeContent(): self
{
$this->content = '';
return $this;
}
public function isInternal(): bool
{
return $this->internal;
}
}