vendor/symfony/ux-twig-component/src/Twig/TwigEnvironmentConfigurator.php line 35

  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\UX\TwigComponent\Twig;
  11. use Symfony\Bundle\TwigBundle\DependencyInjection\Configurator\EnvironmentConfigurator;
  12. use Symfony\UX\TwigComponent\ComponentAttributes;
  13. use Twig\Environment;
  14. use Twig\Extension\EscaperExtension;
  15. /**
  16.  * @final
  17.  */
  18. class TwigEnvironmentConfigurator
  19. {
  20.     public function __construct(
  21.         private readonly EnvironmentConfigurator $decorated,
  22.     ) {
  23.     }
  24.     public function configure(Environment $environment): void
  25.     {
  26.         $this->decorated->configure($environment);
  27.         $environment->setLexer(new ComponentLexer($environment));
  28.         if ($environment->hasExtension(EscaperExtension::class)) {
  29.             $environment->getExtension(EscaperExtension::class)->addSafeClass(ComponentAttributes::class, ['html']);
  30.         }
  31.     }
  32. }