1 | <?php |
||
8 | class Attribute |
||
9 | { |
||
10 | /** |
||
11 | * Store the attribute name. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | private $name; |
||
16 | |||
17 | /** |
||
18 | * Store the attribute value. |
||
19 | * |
||
20 | * @var array|null |
||
21 | */ |
||
22 | private $values; |
||
23 | |||
24 | /** |
||
25 | * Attribute constructor. |
||
26 | * |
||
27 | * @param string $name |
||
28 | * The attribute name. |
||
29 | * @param string $value |
||
30 | * The attribute value. |
||
31 | */ |
||
32 | 10 | public function __construct($name, $value = null) |
|
37 | |||
38 | /** |
||
39 | * Get the attribute name. |
||
40 | * |
||
41 | * @return string |
||
42 | * The attribute name. |
||
43 | */ |
||
44 | public function getName() |
||
48 | |||
49 | /** |
||
50 | * Get the attribute value as a string. |
||
51 | * |
||
52 | * @return string |
||
53 | * The attribute value as a string. |
||
54 | */ |
||
55 | public function getValueAsString() |
||
62 | 5 | ||
63 | /** |
||
64 | 5 | * Get the attribute value as an array. |
|
65 | * |
||
66 | * @return array |
||
67 | * The attribute value as an array. |
||
68 | */ |
||
69 | public function getValueAsArray() |
||
79 | |||
80 | /** |
||
81 | * Convert the object in a string. |
||
82 | * |
||
83 | * @return string |
||
84 | * The attribute as a string. |
||
85 | */ |
||
86 | public function render() |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | public function __toString() |
||
104 | 9 | ||
105 | /** |
||
106 | 9 | * Check if the attribute is a loner attribute. |
|
107 | * |
||
108 | 9 | * @return bool |
|
109 | 8 | * True or False. |
|
110 | */ |
||
111 | public function isLoner() |
||
119 | |||
120 | /** |
||
121 | 9 | * Set the value. |
|
122 | * |
||
123 | 9 | * @param string|null $value |
|
124 | 3 | * The value. |
|
125 | * |
||
126 | * @return \drupol\htmltag\Attribute |
||
127 | 9 | */ |
|
128 | public function set($value = null) |
||
136 | |||
137 | /** |
||
138 | 10 | * Append a value to the attribute. |
|
139 | * |
||
140 | 10 | * @param string $value |
|
141 | 8 | * The value to append. |
|
142 | * |
||
143 | * @return $this |
||
144 | 10 | * The attribute. |
|
145 | */ |
||
146 | public function append($value) |
||
158 | 5 | ||
159 | 5 | /** |
|
160 | 5 | * Merge data into the attribute value. |
|
161 | 5 | * |
|
162 | 5 | * @param array $values |
|
163 | * The values to merge. |
||
164 | * |
||
165 | * @return $this |
||
166 | 5 | * The attribute. |
|
167 | */ |
||
168 | public function merge(array $values) |
||
177 | |||
178 | /** |
||
179 | * Remove a value from the attribute. |
||
180 | * |
||
181 | * @param string $value |
||
182 | * The value to remove. |
||
183 | * |
||
184 | * @return $this |
||
185 | * The attribute. |
||
186 | */ |
||
187 | public function remove($value) |
||
198 | |||
199 | 2 | /** |
|
200 | 2 | * Replace a value of the attribute. |
|
201 | * |
||
202 | 2 | * @param string $original |
|
203 | 2 | * The original value. |
|
204 | * @param string $replacement |
||
205 | * The replacement value. |
||
206 | 2 | * |
|
207 | * @return $this |
||
208 | * The attribute. |
||
209 | */ |
||
210 | public function replace($original, $replacement) |
||
225 | 1 | ||
226 | /** |
||
227 | * Check if the attribute contains a string or a substring. |
||
228 | 1 | * |
|
229 | 1 | * @param string $substring |
|
230 | 1 | * The string to check. |
|
231 | * |
||
232 | * @return bool |
||
233 | 1 | * True or False. |
|
234 | */ |
||
235 | public function contains($substring) |
||
245 | |||
246 | /** |
||
247 | * Set the attribute as a loner attribute. |
||
248 | * |
||
249 | * @param bool $loner |
||
250 | * True or False. |
||
251 | * |
||
252 | * @return $this |
||
253 | * The attribute. |
||
254 | */ |
||
255 | public function setLoner($loner = true) |
||
263 | |||
264 | /** |
||
265 | 1 | * Delete the current attribute. |
|
266 | * |
||
267 | 1 | * @return $this |
|
268 | 1 | * The attribute. |
|
269 | */ |
||
270 | public function delete() |
||
277 | } |
||
278 |