Implement custom parsers/renderers with autowiring for snip content

This commit is contained in:
Tim
2025-04-23 01:06:21 +02:00
parent 5cec259469
commit 943177bc08
15 changed files with 194 additions and 26 deletions

View File

@ -8,7 +8,7 @@ use App\Form\SnipType;
use App\Repository\SnipRepository;
use App\Security\Voter\SnipVoter;
use App\Service\SnipContent\SnipContentService;
use App\Service\SnipParser\Pipeline;
use App\Service\SnipParser\ParserFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
@ -42,23 +42,23 @@ class SnipController extends AbstractController
}
#[Route('/single/{snip}', name: '_single')]
public function single(Snip $snip, Pipeline $pl): Response
public function single(Snip $snip, ParserFactory $pf): Response
{
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip);
return $this->render('snip/single.html.twig', [
'snip' => $snip,
'content' => $pl->parse($this->contentService->getActiveText($snip)),
'content' => $pf->getBySnip($snip)->parseView($this->contentService->getActiveText($snip)),
]);
}
#[Route('/raw/{snip}', name: '_raw')]
public function raw(Snip $snip, Pipeline $pl, Request $request): Response
public function raw(Snip $snip, ParserFactory $pf, Request $request): Response
{
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip);
$response = new Response(
$pl->clean($this->contentService->getActiveText($snip)),
$pf->getBySnip($snip)->parseRaw($this->contentService->getActiveText($snip)),
Response::HTTP_OK,
['Content-Type' => 'text/html']
);