Skip to content

Commit 23d4d60

Browse files
committed
Do not JSON encode stringable values
1 parent 1729c31 commit 23d4d60

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Twig/StimulusTwigExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public function renderStimulusController(Environment $env, $dataOrControllerName
6161
continue;
6262
}
6363

64-
if (!is_scalar($value)) {
64+
if ($value instanceof \Stringable || (is_object($value) && \is_callable([$value, '__toString']))) {
65+
$value = (string) $value;
66+
} elseif (!is_scalar($value)) {
6567
$value = json_encode($value);
66-
}
67-
68-
if (\is_bool($value)) {
68+
} elseif (\is_bool($value)) {
6969
$value = $value ? 'true' : 'false';
7070
}
7171

0 commit comments

Comments
 (0)