Add compare function between snipsContents
This commit is contained in:
41
src/Controller/SnipContentController.php
Normal file
41
src/Controller/SnipContentController.php
Normal 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,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user