Add compare function between snipsContents

This commit is contained in:
Tim
2025-04-23 21:27:47 +02:00
parent 28a2706525
commit cc3e050304
6 changed files with 179 additions and 22 deletions

View File

@ -0,0 +1,41 @@
<?php
namespace App\Controller;
use App\Entity\SnipContent;
use App\Security\Voter\SnipVoter;
use App\Service\SnipContent\MyersDiff;
use App\Service\SnipContent\SnipContentService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/content', name: 'content')]
class SnipContentController extends AbstractController
{
public function __construct(
private readonly SnipContentService $contentService,
) {}
#[Route('/compare/{to}/{from}', name: '_compare')]
public function compare(SnipContent $to, ?SnipContent $from = null): Response
{
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $to->getSnip());
if ($from === null) {
$from = $to->getParent();
}
$diff = MyersDiff::buildDiffLines(
$this->contentService->rebuildText($from),
$this->contentService->rebuildText($to),
);
dump($diff);
return $this->render('content/compare.html.twig', [
'snip' => $to->getSnip(),
'diff' => $diff,
]);
}
}