Skip to content

Commit

Permalink
Do not JSON encode stringable values
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Apr 21, 2022
1 parent 1729c31 commit b7ac5a6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Twig/StimulusTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public function renderStimulusController(Environment $env, $dataOrControllerName
continue;
}

if (!is_scalar($value)) {
if ($value instanceof \Stringable || (\is_object($value) && \is_callable([$value, '__toString']))) {
$value = (string) $value;
} elseif (!\is_scalar($value)) {
$value = json_encode($value);
}

if (\is_bool($value)) {
} elseif (\is_bool($value)) {
$value = $value ? 'true' : 'false';
}

Expand Down

0 comments on commit b7ac5a6

Please sign in to comment.