Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,34 @@ public function withAttribute(string $key, mixed $value): static
return $clone;
}

/**
* Set SEVERAL attributes in one new instance.
*
* Every with*() deep-clones all seven parameter bags, so a chain of them
* pays that price once per link. ResolveStage attaching route_entry,
* route_params and target_service is one logical step, and used to cost
* three full clones of a request nothing had read yet.
*
* Identical in effect to chaining withAttribute(); it just does not build
* the two intermediate requests that get thrown away.
*
* @param array<string, mixed> $attributes
*/
public function withAttributes(array $attributes): static
{
if ($attributes === []) {
return $this;
}

$clone = clone $this;

foreach ($attributes as $key => $value) {
$clone->attributes->set($key, $value);
}

return $clone;
}

public function withIdentity(Identity $identity): static
{
$clone = clone $this;
Expand Down