Skip to content

Commit 3123f35

Browse files
committed
add helpful exception if unable to set attribute
1 parent 585194f commit 3123f35

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/TwigComponent/src/HasAttributesTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public function mountAttributes(array $data): array
3636
$data = array_merge($this->attributes->all(), $data);
3737
}
3838

39+
foreach ($data as $key => $value) {
40+
if (!is_scalar($value)) {
41+
throw new \LogicException(sprintf('Unable to use "%s" (%s) as an attribute. Attributes must be scalar. If you meant to mount this value on your component, make sure this is a writable property.', $key, get_debug_type($value)));
42+
}
43+
}
44+
3945
$this->attributes = new ComponentAttributes($data);
4046

4147
return [];

0 commit comments

Comments
 (0)