@@ -297,12 +297,12 @@ the changes applied and leave the original instance unchanged.
297
297
` Dictionary ` and ` Parameters ` exhibit the following modifying methods:
298
298
299
299
``` php
300
- $map->add($key, $value): static;
301
- $map->append($key, $value): static;
302
- $map->prepend($key, $value): static;
300
+ $map->add(string $key, $value): static;
301
+ $map->append(string $key, $value): static;
302
+ $map->prepend(string $key, $value): static;
303
303
$map->mergeAssociative(...$others): static;
304
304
$map->mergePairs(...$others): static;
305
- $map->remove(...$key): static;
305
+ $map->remove(string ...$key): static;
306
306
```
307
307
308
308
#### Lists
@@ -351,7 +351,7 @@ $list->remove(int ...$key): static;
351
351
352
352
#### Adding and updating parameters
353
353
354
- To ease working with instance that have a ` Parameters ` object attached to the following
354
+ To ease working with instance that have a ` Parameters ` object attached to, the following
355
355
public API is added. It is also possible to instantiate an ` InnerList ` or an ` Item `
356
356
instance with included parameters using one of these named constructors:
357
357
@@ -361,11 +361,30 @@ use Bakame\Http\StructuredFields\Item;
361
361
362
362
//@type SfItemInput ByteSequence|Token|DateTimeInterface|Stringable|string|int|float|bool
363
363
364
- Item::fromAssociative(SfItemInput $value, iterable<string , SfItemInput >|Parameters $parameters = []): self;
365
- Item::fromPair(array{0:SfItemInput, 1:iterable<array {0:string, 1:SfItemInput} >|Parameters } $pair): self;
364
+ Item::fromAssociative(SfItemInput $value, Parameters| iterable<string , SfItemInput > $parameters = []): self;
365
+ Item::fromPair(array{0:SfItemInput, 1:Parameters| iterable<array {0:string, 1:SfItemInput} >} $pair): self;
366
366
367
- InnerList::fromAssociative(iterable<SfItemInput > $members, iterable<string , SfItemInput >|Parameters $parameters): self;
368
- InnerList::fromPair(array{0:iterable<SfItemInput >, iterable<array {0:string, 1:SfItemInput} >|Parameters} $pair): self;
367
+ InnerList::fromAssociative(iterable<SfItemInput > $value, Parameters|iterable<string , SfItemInput > $parameters): self;
368
+ InnerList::fromPair(array{0:iterable<SfItemInput >, Parameters|iterable<array {0:string, 1:SfItemInput} >} $pair): self;
369
+ ```
370
+
371
+ The following example illustrate how to use those methods:
372
+
373
+ ``` php
374
+ use Bakame\Http\StructuredFields\Dictionary;
375
+ use Bakame\Http\StructuredFields\Item;
376
+
377
+ echo Item::fromAssociative(
378
+ Token::fromString('bar'),
379
+ ['baz' => 42]
380
+ )->toHttpValue(), PHP_EOL;
381
+
382
+ echo Item::fromPair([
383
+ Token::fromString('bar'),
384
+ [['baz', 42]],
385
+ ])->toHttpValue(), PHP_EOL;
386
+
387
+ //both methods return `bar;baz=42`
369
388
```
370
389
371
390
Both classes allow return their respective pair representation via the ` toPair ` method.
0 commit comments