Skip to content

Commit 5e4ba9f

Browse files
committed
minor #1824 [Stimulus] Use Twig >3.9 'EscaperRuntime' (smnandre)
This PR was merged into the 2.x branch. Discussion ---------- [Stimulus] Use Twig >3.9 'EscaperRuntime' | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Issues | Fix #... | License | MIT Resolves CI deprecations (for > Twig 3.9) Twig introduction of EscaperRuntime here: twigphp/Twig#4055 Commits ------- 1fe2ae3 [Stimulus] Use Twig >3.9 'EscaperRuntime'
2 parents bd53d73 + 1fe2ae3 commit 5e4ba9f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/StimulusBundle/src/Dto/StimulusAttributes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Twig\Environment;
1717
use Twig\Extension\EscaperExtension;
18+
use Twig\Runtime\EscaperRuntime;
1819

1920
/**
2021
* Helper to build Stimulus-related HTML attributes.
@@ -215,6 +216,10 @@ private function getFormattedValue(mixed $value): string
215216

216217
private function escapeAsHtmlAttr(mixed $value): string
217218
{
219+
if (class_exists(EscaperRuntime::class)) {
220+
return $this->env->getRuntime(EscaperRuntime::class)->escape($value, 'html_attr');
221+
}
222+
218223
if (method_exists(EscaperExtension::class, 'escape')) {
219224
return EscaperExtension::escape($this->env, $value, 'html_attr');
220225
}

0 commit comments

Comments
 (0)