37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?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() {}
|
|
|
|
#[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(
|
|
SnipContentService::rebuildText($from),
|
|
SnipContentService::rebuildText($to),
|
|
);
|
|
|
|
return $this->render('content/compare.html.twig', [
|
|
'snip' => $to->getSnip(),
|
|
'diff' => $diff,
|
|
]);
|
|
}
|
|
} |