src/Controller/Frontend/IndexController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Business\Cart\Session\CartSessionHandlerInterface;
  4. use App\Business\Frontend\Index\IndexDataProviderInterface;
  5. use App\Entity\Customer;
  6. use App\Service\Utils\CustomerServiceInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class IndexController extends AbstractController
  11. {
  12.     protected ?Customer $customer;
  13.     protected CartSessionHandlerInterface $cartSessionHandler;
  14.     /**
  15.      * @param CustomerServiceInterface $customerService
  16.      * @param CartSessionHandlerInterface $cartSessionHandler
  17.      */
  18.     public function __construct(
  19.         CustomerServiceInterface $customerService,
  20.         CartSessionHandlerInterface $cartSessionHandler
  21.     ) {
  22.         $this->customer $customerService->getCustomerByHost();
  23.         $this->cartSessionHandler $cartSessionHandler;
  24.     }
  25.     /**
  26.      * @param IndexDataProviderInterface $dataProvider
  27.      *
  28.      * @return Response
  29.      */
  30.     #[Route('/'name'app_frontend_index')]
  31.     public function index(IndexDataProviderInterface $dataProvider): Response
  32.     {
  33.         if ($this->customer === null) {
  34.             return $this->redirectToRoute('app_frontend_customer_not_found');
  35.         }
  36.         return $this->render('frontend/index/index.html.twig', [
  37.             'sortedAreasArray' => $dataProvider->getCustomerPackagePlacesAndAreas(),
  38.             'latestSponsors' => $dataProvider->getLatestSponsors(4),
  39.         ]);
  40.     }
  41.     /**
  42.      * @return Response
  43.      */
  44.     #[Route('/not-found'name'app_frontend_customer_not_found')]
  45.     public function customerNotFound(): Response
  46.     {
  47.         return $this->render('frontend/index/customer_not_found.html.twig', [
  48.             'controller_name' => 'MainController',
  49.         ]);
  50.     }
  51.     /**
  52.      * @return Response
  53.      */
  54.     #[Route('/customer_styles.css'name'app_frontend_customer_css')]
  55.     public function customerCSS(): Response
  56.     {
  57.         $response = new Response();
  58.         $response->headers->set('Content-Type''text/css');
  59.         return $this->render('frontend/css/customer_styles.css.twig', [
  60.             'customer' => $this->customer
  61.         ], $response);
  62.     }
  63. }