9
9
use IteratorAggregate ;
10
10
use function array_key_exists ;
11
11
use function array_keys ;
12
+ use function array_map ;
12
13
use function count ;
13
14
use function implode ;
15
+ use function is_array ;
14
16
use function preg_match ;
15
17
16
18
/**
@@ -38,10 +40,7 @@ public static function __set_state(array $properties): self
38
40
* its keys represent the dictionary entry key
39
41
* its values represent the dictionary entry value
40
42
*
41
- * @param iterable<string, InnerList|Item|ByteSequence|Token|array{
42
- * 0:array<Item|ByteSequence|Token|bool|int|float|string>,
43
- * 1:array<string,Item|ByteSequence|Token|bool|int|float|string>
44
- * }|bool|int|float|string> $members
43
+ * @param iterable<string, InnerList|Item|ByteSequence|Token|bool|int|float|string> $members
45
44
*/
46
45
public static function fromAssociative (iterable $ members = []): self
47
46
{
@@ -60,10 +59,7 @@ public static function fromAssociative(iterable $members = []): self
60
59
* the first member represents the instance entry key
61
60
* the second member represents the instance entry value
62
61
*
63
- * @param iterable<array{0:string, 1:InnerList|Item|ByteSequence|Token|array{
64
- * 0:array<Item|ByteSequence|Token|bool|int|float|string>,
65
- * 1:array<string,Item|ByteSequence|Token|bool|int|float|string>
66
- * }|bool|int|float|string}> $pairs
62
+ * @param iterable<array{0:string, 1:InnerList|Item|ByteSequence|Token|bool|int|float|string}> $pairs
67
63
*/
68
64
public static function fromPairs (iterable $ pairs = []): self
69
65
{
@@ -82,7 +78,10 @@ public static function fromPairs(iterable $pairs = []): self
82
78
*/
83
79
public static function fromHttpValue (string $ httpValue ): self
84
80
{
85
- return self ::fromAssociative (Parser::parseDictionary ($ httpValue ));
81
+ return self ::fromAssociative (array_map (
82
+ fn (mixed $ value ): mixed => is_array ($ value ) ? InnerList::fromList (...$ value ) : $ value ,
83
+ Parser::parseDictionary ($ httpValue )
84
+ ));
86
85
}
87
86
88
87
public function toHttpValue (): string
@@ -216,13 +215,8 @@ public function pair(int $index): array
216
215
217
216
/**
218
217
* Add a member at the end of the instance if the key is new otherwise update the value associated with the key.
219
- *
220
- * @param InnerList|Item|ByteSequence|Token|array{
221
- * 0:array<Item|ByteSequence|Token|bool|int|float|string>,
222
- * 1:array<string,Item|ByteSequence|Token|bool|int|float|string>
223
- * }|bool|int|float|string $member
224
218
*/
225
- public function set (string $ key , InnerList |Item |ByteSequence |Token |array | bool |int |float |string $ member ): self
219
+ public function set (string $ key , InnerList |Item |ByteSequence |Token |bool |int |float |string $ member ): self
226
220
{
227
221
$ this ->members [self ::filterKey ($ key )] = self ::filterMember ($ member );
228
222
@@ -241,17 +235,10 @@ private static function filterKey(string $key): string
241
235
return $ key ;
242
236
}
243
237
244
- /**
245
- * @param InnerList|Item|ByteSequence|Token|array{
246
- * 0:array<Item|ByteSequence|Token|bool|int|float|string>,
247
- * 1:array<string,Item|ByteSequence|Token|bool|int|float|string>
248
- * }|bool|int|float|string $member
249
- */
250
- private static function filterMember (InnerList |Item |ByteSequence |Token |array |bool |int |float |string $ member ): InnerList |Item
238
+ private static function filterMember (InnerList |Item |ByteSequence |Token |bool |int |float |string $ member ): InnerList |Item
251
239
{
252
240
return match (true ) {
253
241
$ member instanceof InnerList, $ member instanceof Item => $ member ,
254
- is_array ($ member ) => InnerList::fromList (...$ member ),
255
242
default => Item::from ($ member ),
256
243
};
257
244
}
@@ -280,13 +267,8 @@ public function clear(): self
280
267
281
268
/**
282
269
* Add a member at the end of the instance if the key is new delete any previous reference to the key.
283
- *
284
- * @param InnerList|Item|ByteSequence|Token|array{
285
- * 0:array<Item|ByteSequence|Token|bool|int|float|string>,
286
- * 1:array<string,Item|ByteSequence|Token|bool|int|float|string>
287
- * }|bool|int|float|string $member
288
270
*/
289
- public function append (string $ key , InnerList |Item |ByteSequence |Token |array | bool |int |float |string $ member ): self
271
+ public function append (string $ key , InnerList |Item |ByteSequence |Token |bool |int |float |string $ member ): self
290
272
{
291
273
unset($ this ->members [$ key ]);
292
274
@@ -297,13 +279,8 @@ public function append(string $key, InnerList|Item|ByteSequence|Token|array|bool
297
279
298
280
/**
299
281
* Add a member at the beginning of the instance if the key is new delete any previous reference to the key.
300
- *
301
- * @param InnerList|Item|ByteSequence|Token|array{
302
- * 0:array<Item|ByteSequence|Token|bool|int|float|string>,
303
- * 1:array<string,Item|ByteSequence|Token|bool|int|float|string>
304
- * }|bool|int|float|string $member
305
282
*/
306
- public function prepend (string $ key , InnerList |Item |ByteSequence |Token |array | bool |int |float |string $ member ): self
283
+ public function prepend (string $ key , InnerList |Item |ByteSequence |Token |bool |int |float |string $ member ): self
307
284
{
308
285
unset($ this ->members [$ key ]);
309
286
@@ -315,10 +292,7 @@ public function prepend(string $key, InnerList|Item|ByteSequence|Token|array|boo
315
292
/**
316
293
* Merge multiple instances.
317
294
*
318
- * @param iterable<array-key, InnerList|Item|ByteSequence|Token|array{
319
- * 0:array<Item|ByteSequence|Token|bool|int|float|string>,
320
- * 1:array<string,Item|ByteSequence|Token|bool|int|float|string>
321
- * }|bool|int|float|string> ...$others
295
+ * @param iterable<array-key, InnerList|Item|ByteSequence|Token|bool|int|float|string> ...$others
322
296
*/
323
297
public function merge (iterable ...$ others ): self
324
298
{
0 commit comments