<?php
namespace App\Controller;
use App\Repository\EvenementRepository;
use App\Repository\RealisationRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Contracts\Cache\ItemInterface;
class HomeController extends AbstractController
{
private $realisationRepository;
private $evenementRepository;
public function __construct(RealisationRepository $realisationRepository, EvenementRepository $evenementRepository)
{
$this->realisationRepository = $realisationRepository;
$this->evenementRepository = $evenementRepository;
}
/**
* @Route("/", name="home")
*/
public function index(): Response
{
$cache = new FilesystemAdapter();
$lastsReal = $cache->get('home-lastsReal', function (ItemInterface $item) {
$item->expiresAfter(6);
return $this->realisationRepository->findLasts(4);
});
$lastsEvent = $cache->get('home-lastsEvent', function (ItemInterface $item) {
$item->expiresAfter(6);
return $this->evenementRepository->findLasts(5);
//return $this->evenementRepository->eventAfter();
});
return $this->render('home/index.html.twig', [
'lastsReal' => $lastsReal,
'lastsEvent' => $lastsEvent,
]);
}
}