Skip to content

Commit

Permalink
Merge pull request #22 from rekalogika:feat/context-with-multiple-arg…
Browse files Browse the repository at this point in the history
…ument

feat(`Context`): `with()` not accepts multiple argument.
  • Loading branch information
priyadi committed Feb 20, 2024
2 parents 60b8f35 + 9b91d7b commit 7d0c050
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* feat: Supports dynamic properties (including `stdClass`) on the target side.
* fix(`Mapper`): Fix typehint.
* test: test array cast to object mapping
* feat(`Context`): `with()` not accepts multiple argument.

## 1.0.0

Expand Down
9 changes: 6 additions & 3 deletions src/Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ private static function createFrom(array $context): self
return new self($context);
}

public function with(object $value): self
public function with(object ...$value): self
{
$class = get_class($value);
$context = $this->context;
$context[$class] = $value;

foreach ($value as $object) {
$class = get_class($object);
$context[$class] = $object;
}

return self::createFrom($context);
}
Expand Down

0 comments on commit 7d0c050

Please sign in to comment.