39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\Snip;
|
|
use App\Entity\SnipContent;
|
|
use App\Security\Voter\SnipVoter;
|
|
use App\Service\SnipServiceFactory;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
#[Route('/version/{snip}', name: 'version')]
|
|
class VersionController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly SnipServiceFactory $snipServiceFactory,
|
|
) {}
|
|
|
|
#[Route('/', name: '_index')]
|
|
public function index(Snip $snip): Response
|
|
{
|
|
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
|
|
|
|
return $this->render('version/index.html.twig', [
|
|
'snip' => $snip,
|
|
]);
|
|
}
|
|
|
|
#[Route('/set/{version}', name: '_set')]
|
|
public function set(Snip $snip, SnipContent $version): Response
|
|
{
|
|
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
|
|
|
|
$this->snipServiceFactory->create($snip)->setVersion($version);
|
|
$this->addFlash('success', 'Snip version set to ' . $version->getId());
|
|
return $this->redirectToRoute('snip_single', ['snip' => $snip->getId()]);
|
|
}
|
|
} |