vendor/shopware/core/Framework/Adapter/Twig/Extension/SwSanitizeTwigFilter.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Adapter\Twig\Extension;
  3. use Shopware\Core\Framework\Log\Package;
  4. use Shopware\Core\Framework\Util\HtmlSanitizer;
  5. use Twig\Extension\AbstractExtension;
  6. use Twig\TwigFilter;
  7. #[Package('core')]
  8. class SwSanitizeTwigFilter extends AbstractExtension
  9. {
  10.     private HtmlSanitizer $sanitizer;
  11.     /**
  12.      * @internal
  13.      */
  14.     public function __construct(HtmlSanitizer $sanitizer)
  15.     {
  16.         $this->sanitizer $sanitizer;
  17.     }
  18.     public function getFilters(): array
  19.     {
  20.         return [
  21.             new TwigFilter('sw_sanitize', [$this'sanitize'], ['is_safe' => ['html']]),
  22.         ];
  23.     }
  24.     public function sanitize(string $text, ?array $options = [], bool $override false): string
  25.     {
  26.         return $this->sanitizer->sanitize($text$options$override);
  27.     }
  28. }