src/Controller/ShopController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Helper\LastModifyHelper;
  4. use App\Repository\ShopExampleRepository;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpKernel\KernelInterface;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class ShopController extends AbstractController
  10. {
  11.     private LastModifyHelper $tracker;
  12.     public function __construct(KernelInterface $appKernel)
  13.     {
  14.         $this->tracker = new LastModifyHelper($appKernel);
  15.     }
  16.     /**
  17.      * @Route("/shop", name="shop.ru")
  18.      */
  19.     public function index(ShopExampleRepository $repository): Response
  20.     {
  21.         $template 'shop/index.html.twig';
  22.         $modified $this->tracker->get($template);
  23.         $response $this->render($template, [
  24.             'examples' => $repository->findAllOrdered(),
  25.             'modified' => $modified,
  26.         ]);
  27.         $response->headers->set('Last-Modified'$modified);
  28.         return $response;
  29.     }
  30. }