Skip to content

Commit db43b81

Browse files
committed
add attribute bag defaults
1 parent e50dbfd commit db43b81

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/TwigComponent/src/AttributeBag.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,23 @@ public function reject(string ...$keys): self
8080

8181
return $clone;
8282
}
83+
84+
/**
85+
* @param array<string, string> $attributes
86+
*/
87+
public function defaults(array $attributes): self
88+
{
89+
$clone = $this;
90+
91+
foreach ($attributes as $attribute => $value) {
92+
$clone->attributes[$attribute] = $clone->attributes[$attribute] ?? $value;
93+
}
94+
95+
return $clone;
96+
}
97+
98+
public function default(string $attribute, string $value): self
99+
{
100+
return $this->defaults([$attribute => $value]);
101+
}
83102
}

0 commit comments

Comments
 (0)