Allow going back to a previous commit
This commit is contained in:
36
src/Controller/HistoryController.php
Normal file
36
src/Controller/HistoryController.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Snip;
|
||||
use App\Service\SnipServiceFactory;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
#[Route('/history/{snip}', name: 'history')]
|
||||
class HistoryController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SnipServiceFactory $snipServiceFactory,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/', name: '_index')]
|
||||
public function index(Snip $snip): Response
|
||||
{
|
||||
return $this->render('history/index.html.twig', [
|
||||
'snip' => $snip,
|
||||
'commits' => $this->snipServiceFactory->create($snip)->getRepo()->getAllCommits(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/set/{commit}', name: '_set')]
|
||||
public function set(Snip $snip, string $commit): Response
|
||||
{
|
||||
$this->snipServiceFactory->create($snip)->getRepo()->checkout($commit);
|
||||
$this->addFlash('success', 'Snip version set to ' . $commit);
|
||||
return $this->redirectToRoute('snip_single', ['snip' => $snip->getId()]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user