File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
# CHANGELOG
2
2
3
+ ## Unreleased
4
+
5
+ - Make ` ComponentAttributes ` traversable/countable.
6
+
3
7
## 2.13.0
4
8
5
9
- [ BC BREAK] Add component metadata to ` PreMountEvent ` and ` PostMountEvent `
Original file line number Diff line number Diff line change 19
19
*
20
20
* @immutable
21
21
*/
22
- final class ComponentAttributes
22
+ final class ComponentAttributes implements \IteratorAggregate, \Countable
23
23
{
24
24
/**
25
25
* @param array<string, string|bool> $attributes
@@ -157,4 +157,14 @@ public function remove($key): self
157
157
158
158
return new self ($ attributes );
159
159
}
160
+
161
+ public function getIterator (): \Traversable
162
+ {
163
+ return new \ArrayIterator ($ this ->attributes );
164
+ }
165
+
166
+ public function count (): int
167
+ {
168
+ return \count ($ this ->attributes );
169
+ }
160
170
}
Original file line number Diff line number Diff line change @@ -191,4 +191,12 @@ public function testNullBehaviour(): void
191
191
$ this ->assertSame (['disabled ' => null ], $ attributes ->all ());
192
192
$ this ->assertSame (' disabled ' , (string ) $ attributes );
193
193
}
194
+
195
+ public function testIsTraversableAndCountable (): void
196
+ {
197
+ $ attributes = new ComponentAttributes (['foo ' => 'bar ' ]);
198
+
199
+ $ this ->assertSame ($ attributes ->all (), iterator_to_array ($ attributes ));
200
+ $ this ->assertCount (1 , $ attributes );
201
+ }
194
202
}
You can’t perform that action at this time.
0 commit comments