vendor/exercise/htmlpurifier-bundle/src/Twig/HTMLPurifierRuntime.php line 41

Open in your IDE?
  1. <?php
  2. namespace Exercise\HTMLPurifierBundle\Twig;
  3. use Exercise\HTMLPurifierBundle\HTMLPurifiersRegistryInterface;
  4. use Twig\Extension\RuntimeExtensionInterface;
  5. class HTMLPurifierRuntime implements RuntimeExtensionInterface
  6. {
  7.     private $purifiersRegistry;
  8.     public function __construct(HTMLPurifiersRegistryInterface $registry)
  9.     {
  10.         $this->purifiersRegistry $registry;
  11.     }
  12.     /**
  13.      * Filters the input through an \HTMLPurifier service.
  14.      *
  15.      * @param string|null $string  The html string to purify
  16.      * @param string      $profile A configuration profile name
  17.      *
  18.      * @return string The purified html string
  19.      */
  20.     public function purify(?string $stringstring $profile 'default'): string
  21.     {
  22.         if (null === $string) {
  23.             return '';
  24.         }
  25.         return $this->getHTMLPurifierForProfile($profile)->purify($string);
  26.     }
  27.     /**
  28.      * Gets the HTMLPurifier service corresponding to the given profile.
  29.      *
  30.      * @throws \InvalidArgumentException If the profile does not exist
  31.      */
  32.     private function getHTMLPurifierForProfile(string $profile): \HTMLPurifier
  33.     {
  34.         return $this->purifiersRegistry->get($profile);
  35.     }
  36. }