Skip to content

Commit a1f988b

Browse files
committed
Adding merge method to Dictionary and Parameters
1 parent 9cbf915 commit a1f988b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
2121
- `Parameters::valueByKey`
2222
- `Parameters::valueByIndex`
2323
- Added a validation mechanism to facilitate `Item` and `Parameters` validation against field definition.
24+
- `Dictionary::mergeParametersByPairs`, `Dictionary::mergeParametersByAssociative`
25+
- `Parameters::mergeParametersByPairs`, `Parameters::mergeParametersByAssociative`
2426

2527
### Fixed
2628

src/ParameterAccess.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,30 @@ public function filterParameters(callable $callback): static
231231
{
232232
return $this->withParameters($this->parameters()->filter($callback));
233233
}
234+
235+
/**
236+
* Merges multiple instances using iterable pairs.
237+
*
238+
* This method MUST retain the state of the current instance, and return
239+
* an instance that contains the specified changes.
240+
*
241+
* @param StructuredFieldProvider|Parameters|Dictionary|iterable<array{0:string, 1:SfItemInput}> ...$others
242+
*/
243+
public function mergeParametersByPairs(...$others): static
244+
{
245+
return $this->withParameters($this->parameters()->mergePairs(...$others));
246+
}
247+
248+
/**
249+
* Merges multiple instances using iterable associative.
250+
*
251+
* This method MUST retain the state of the current instance, and return
252+
* an instance that contains the specified changes.
253+
*
254+
* @param StructuredFieldProvider|Dictionary|Parameters|iterable<string, SfItemInput> ...$others
255+
*/
256+
public function mergeParametersByAssociative(...$others): static
257+
{
258+
return $this->withParameters($this->parameters()->mergeAssociative(...$others));
259+
}
234260
}

0 commit comments

Comments
 (0)