. */ declare(strict_types=1); namespace App\Twig\Sandbox; use App\Services\LabelSystem\LabelTextReplacer; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; use Twig\TwigFunction; class SandboxedLabelExtension extends AbstractExtension { public function __construct(private readonly LabelTextReplacer $labelTextReplacer) { } public function getFunctions(): array { return [ new TwigFunction('placeholder', fn(string $text, object $label_target) => $this->labelTextReplacer->handlePlaceholderOrReturnNull($text, $label_target)), ]; } public function getFilters(): array { return [ new TwigFilter('placeholders', fn(string $text, object $label_target) => $this->labelTextReplacer->replace($text, $label_target)), ]; } }