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 | * Create a copy of the current attribute with specific value. |
||
40 | * |
||
41 | * @param string $value |
||
42 | * The attribute value. |
||
43 | * |
||
44 | * @return \drupol\htmltag\Attribute |
||
45 | * The attribute. |
||
46 | */ |
||
47 | 3 | public function withValue($value) |
|
55 | |||
56 | /** |
||
57 | * Get the attribute name. |
||
58 | * |
||
59 | * @return string |
||
60 | * The attribute name. |
||
61 | */ |
||
62 | 5 | public function getName() |
|
66 | |||
67 | /** |
||
68 | * Get the attribute value as a string. |
||
69 | * |
||
70 | * @return string |
||
71 | * The attribute value as a string. |
||
72 | */ |
||
73 | 8 | public function getValueAsString() |
|
80 | |||
81 | /** |
||
82 | * Get the attribute value as an array. |
||
83 | * |
||
84 | * @return array |
||
85 | * The attribute value as an array. |
||
86 | */ |
||
87 | 9 | public function getValueAsArray() |
|
97 | |||
98 | /** |
||
99 | * Convert the object in a string. |
||
100 | * |
||
101 | * @return string |
||
102 | * The attribute as a string. |
||
103 | */ |
||
104 | 9 | public function __toString() |
|
114 | |||
115 | /** |
||
116 | * Check if the attribute is a loner attribute. |
||
117 | * |
||
118 | * @return bool |
||
119 | * True or False. |
||
120 | */ |
||
121 | 9 | public function isLoner() |
|
129 | |||
130 | /** |
||
131 | * Set the value. |
||
132 | * |
||
133 | * @param string|null $value |
||
134 | * The value. |
||
135 | * |
||
136 | * @return \drupol\htmltag\Attribute |
||
137 | */ |
||
138 | 10 | public function set($value = null) |
|
146 | |||
147 | /** |
||
148 | * Append a value to the attribute. |
||
149 | * |
||
150 | * @param string $value |
||
151 | * The value to append. |
||
152 | * |
||
153 | * @return $this |
||
154 | * The attribute. |
||
155 | */ |
||
156 | 5 | public function append($value) |
|
168 | |||
169 | /** |
||
170 | * Merge data into the attribute value. |
||
171 | * |
||
172 | * @param array $values |
||
173 | * The values to merge. |
||
174 | * |
||
175 | * @return $this |
||
176 | * The attribute. |
||
177 | */ |
||
178 | public function merge(array $values) |
||
187 | |||
188 | /** |
||
189 | * Remove a value from the attribute. |
||
190 | * |
||
191 | * @param string $value |
||
192 | * The value to remove. |
||
193 | * |
||
194 | * @return $this |
||
195 | * The attribute. |
||
196 | */ |
||
197 | 2 | public function remove($value) |
|
208 | |||
209 | /** |
||
210 | * Replace a value of the attribute. |
||
211 | * |
||
212 | * @param string $original |
||
213 | * The original value. |
||
214 | * @param string $replacement |
||
215 | * The replacement value. |
||
216 | * |
||
217 | * @return $this |
||
218 | * The attribute. |
||
219 | */ |
||
220 | 1 | public function replace($original, $replacement) |
|
235 | |||
236 | /** |
||
237 | * Check if the attribute contains a string or a substring. |
||
238 | * |
||
239 | * @param string $substring |
||
240 | * The string to check. |
||
241 | * |
||
242 | * @return bool |
||
243 | * True or False. |
||
244 | */ |
||
245 | public function contains($substring) |
||
255 | |||
256 | /** |
||
257 | * Set the attribute as a loner attribute. |
||
258 | * |
||
259 | * @param bool $loner |
||
260 | * True or False. |
||
261 | * |
||
262 | * @return $this |
||
263 | * The attribute. |
||
264 | */ |
||
265 | 1 | public function setLoner($loner = true) |
|
273 | |||
274 | /** |
||
275 | * Delete the current attribute. |
||
276 | * |
||
277 | * @return $this |
||
278 | * The attribute. |
||
279 | */ |
||
280 | public function delete() |
||
287 | } |
||
288 |