1 | <?php |
||
12 | class Tag |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * The name of the tag. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $name; |
||
21 | |||
22 | /** |
||
23 | * The attributes of the tag. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $attr = []; |
||
28 | |||
29 | /** |
||
30 | * Is this tag self closing. |
||
31 | * |
||
32 | * @var bool |
||
33 | */ |
||
34 | protected $selfClosing = false; |
||
35 | |||
36 | /** |
||
37 | * If self-closing, will this use a trailing slash. /> |
||
38 | * |
||
39 | * @var bool |
||
40 | */ |
||
41 | protected $trailingSlash = true; |
||
42 | |||
43 | /** |
||
44 | * Tag noise |
||
45 | */ |
||
46 | protected $noise = ''; |
||
47 | |||
48 | /** |
||
49 | * The encoding class to... encode the tags |
||
50 | * |
||
51 | * @var mixed |
||
52 | */ |
||
53 | protected $encode = null; |
||
54 | |||
55 | /** |
||
56 | * Sets up the tag with a name. |
||
57 | * |
||
58 | * @param $name |
||
59 | */ |
||
60 | 390 | public function __construct(string $name) |
|
64 | |||
65 | /** |
||
66 | * Magic method to get any of the attributes. |
||
67 | * |
||
68 | * @param string $key |
||
69 | * @return mixed |
||
70 | */ |
||
71 | 12 | public function __get($key) |
|
75 | |||
76 | /** |
||
77 | * Magic method to set any attribute. |
||
78 | * |
||
79 | * @param string $key |
||
80 | * @param mixed $value |
||
81 | */ |
||
82 | 189 | public function __set($key, $value) |
|
86 | |||
87 | /** |
||
88 | * Returns the name of this tag. |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | 264 | public function name(): string |
|
96 | |||
97 | /** |
||
98 | * Sets the tag to be self closing. |
||
99 | * |
||
100 | * @return Tag |
||
101 | * @chainable |
||
102 | */ |
||
103 | 168 | public function selfClosing(): Tag |
|
109 | |||
110 | |||
111 | /** |
||
112 | * Sets the tag to not use a trailing slash. |
||
113 | * |
||
114 | * @return Tag |
||
115 | * @chainable |
||
116 | */ |
||
117 | 3 | public function noTrailingSlash(): Tag |
|
123 | |||
124 | /** |
||
125 | * Checks if the tag is self closing. |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | 228 | public function isSelfClosing(): bool |
|
133 | |||
134 | /** |
||
135 | * Sets the encoding type to be used. |
||
136 | * |
||
137 | * @param Encode $encode |
||
138 | * @return void |
||
139 | */ |
||
140 | 189 | public function setEncoding(Encode $encode): void |
|
144 | |||
145 | /** |
||
146 | * Sets the noise for this tag (if any) |
||
147 | * |
||
148 | * @param string $noise |
||
149 | * @return Tag |
||
150 | * @chainable |
||
151 | */ |
||
152 | 3 | public function noise(string $noise): Tag |
|
158 | |||
159 | /** |
||
160 | * Set an attribute for this tag. |
||
161 | * |
||
162 | * @param string $key |
||
163 | * @param string|array $value |
||
164 | * @return Tag |
||
165 | * @chainable |
||
166 | */ |
||
167 | 291 | public function setAttribute(string $key, $value): Tag |
|
180 | |||
181 | /** |
||
182 | * Set inline style attribute value. |
||
183 | * |
||
184 | * @param mixed $attr_key |
||
185 | * @param mixed $attr_value |
||
186 | */ |
||
187 | 6 | public function setStyleAttributeValue($attr_key, $attr_value): void |
|
200 | |||
201 | /** |
||
202 | * Get style attribute in array |
||
203 | * |
||
204 | * @return array |
||
205 | */ |
||
206 | 6 | public function getStyleAttributeArray(): array |
|
223 | |||
224 | |||
225 | |||
226 | /** |
||
227 | * Removes an attribute from this tag. |
||
228 | * |
||
229 | * @param mixed $key |
||
230 | * @return void |
||
231 | */ |
||
232 | 6 | public function removeAttribute($key) |
|
237 | |||
238 | /** |
||
239 | * Removes all attributes on this tag. |
||
240 | * |
||
241 | * @return void |
||
242 | */ |
||
243 | 6 | public function removeAllAttributes() |
|
247 | |||
248 | /** |
||
249 | * Sets the attributes for this tag |
||
250 | * |
||
251 | * @param array $attr |
||
252 | * @return $this |
||
253 | */ |
||
254 | 75 | public function setAttributes(array $attr) |
|
262 | |||
263 | /** |
||
264 | * Returns all attributes of this tag. |
||
265 | * |
||
266 | * @return array |
||
267 | */ |
||
268 | 9 | public function getAttributes() |
|
277 | |||
278 | /** |
||
279 | * Returns an attribute by the key |
||
280 | * |
||
281 | * @param string $key |
||
282 | * @return mixed |
||
283 | */ |
||
284 | 276 | public function getAttribute(string $key) |
|
297 | |||
298 | /** |
||
299 | * Returns TRUE if node has attribute |
||
300 | * |
||
301 | * @param string $key |
||
302 | * @return bool |
||
303 | */ |
||
304 | 84 | public function hasAttribute(string $key) |
|
308 | |||
309 | /** |
||
310 | * Generates the opening tag for this object. |
||
311 | * |
||
312 | * @return string |
||
313 | */ |
||
314 | 138 | public function makeOpeningTag() |
|
337 | |||
338 | /** |
||
339 | * Generates the closing tag for this object. |
||
340 | * |
||
341 | * @return string |
||
342 | */ |
||
343 | 123 | public function makeClosingTag() |
|
351 | } |
||
352 |