Files
newssubmission-bundle/src/Service/NewsContentSanitizer.php
T
2026-03-08 18:01:52 +01:00

30 lines
684 B
PHP

<?php
declare(strict_types=1);
namespace Mummert\NewsSubmissionBundle\Service;
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
class NewsContentSanitizer
{
private readonly HtmlSanitizer $sanitizer;
public function __construct()
{
$config = new HtmlSanitizerConfig();
foreach (['p', 'h2', 'h3', 'strong', 'em', 'u', 'ul', 'ol', 'li'] as $tag) {
$config = $config->allowElement($tag);
}
$this->sanitizer = new HtmlSanitizer($config);
}
public function sanitize(string $html): string
{
return trim($this->sanitizer->sanitize($html));
}
}