1 | <?php |
||
12 | class Attributes extends AbstractBaseHtmlTagObject implements AttributesInterface |
||
13 | { |
||
14 | /** |
||
15 | * Stores the attribute data. |
||
16 | * |
||
17 | * @var \drupol\htmltag\Attribute\AttributeInterface[] |
||
18 | */ |
||
19 | private $storage = []; |
||
20 | |||
21 | /** |
||
22 | * The attribute factory. |
||
23 | * |
||
24 | * @var \drupol\htmltag\Attribute\AttributeFactoryInterface |
||
25 | */ |
||
26 | private $attributeFactory; |
||
27 | |||
28 | /** |
||
29 | * Attributes constructor. |
||
30 | * |
||
31 | * @param \drupol\htmltag\Attribute\AttributeFactoryInterface $attributeFactory |
||
32 | * The attribute factory. |
||
33 | * @param mixed[] $data |
||
34 | * The input attributes. |
||
35 | */ |
||
36 | 40 | public function __construct(AttributeFactoryInterface $attributeFactory, array $data = []) |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 40 | public function import($data) |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 2 | public function set($key, ...$value) |
|
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 4 | public function offsetGet($key) |
|
68 | { |
||
69 | $this->storage += [ |
||
70 | 4 | $key => $this->attributeFactory->getInstance($key) |
|
71 | ]; |
||
72 | |||
73 | 4 | return $this->storage[$key]; |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | 1 | public function offsetSet($key, $value = null) |
|
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | 1 | public function offsetUnset($key) |
|
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | 2 | public function offsetExists($key) |
|
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | 16 | public function append($key, ...$values) |
|
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | 2 | public function remove($key, ...$values) |
|
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | 2 | public function delete(...$keys) |
|
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | 1 | public function without(...$keys) |
|
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | 1 | public function replace($key, $value, ...$replacements) |
|
152 | { |
||
153 | 1 | if (!$this->contains($key, $value)) { |
|
154 | 1 | return $this; |
|
155 | } |
||
156 | |||
157 | 1 | $this->storage[$key]->replace($value, $replacements); |
|
158 | |||
159 | 1 | return $this; |
|
160 | } |
||
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | */ |
||
165 | 1 | public function merge(array ...$dataset) |
|
175 | |||
176 | /** |
||
177 | * {@inheritdoc} |
||
178 | */ |
||
179 | 3 | public function exists($key, ...$values) |
|
189 | |||
190 | /** |
||
191 | * {@inheritdoc} |
||
192 | */ |
||
193 | 3 | public function contains($key, ...$values) |
|
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | 1 | public function __toString() |
|
205 | |||
206 | /** |
||
207 | * {@inheritdoc} |
||
208 | */ |
||
209 | 24 | public function render() |
|
210 | { |
||
211 | 24 | $output = ''; |
|
212 | |||
213 | 24 | foreach ($this->getStorage() as $attribute) { |
|
214 | 19 | $output .= ' ' . $attribute->render(); |
|
215 | } |
||
216 | |||
217 | 24 | return $output; |
|
218 | } |
||
219 | |||
220 | /** |
||
221 | * {@inheritdoc} |
||
222 | */ |
||
223 | 30 | public function getStorage() |
|
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | 1 | public function getIterator() |
|
235 | |||
236 | /** |
||
237 | * {@inheritdoc} |
||
238 | */ |
||
239 | 1 | public function count() |
|
243 | |||
244 | /** |
||
245 | * {@inheritdoc} |
||
246 | */ |
||
247 | 3 | public function getValuesAsArray() |
|
257 | |||
258 | /** |
||
259 | * {@inheritdoc} |
||
260 | */ |
||
261 | 1 | public function serialize() |
|
267 | |||
268 | /** |
||
269 | * {@inheritdoc} |
||
270 | */ |
||
271 | 1 | public function unserialize($serialized) |
|
284 | |||
285 | /** |
||
286 | * {@inheritdoc} |
||
287 | */ |
||
288 | protected function escape($value) |
||
292 | } |
||
293 |