src/EventListener/DailyMaintenanceListener.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\VignetteMaintenance\VignetteMaintenance;
  4. use App\Service\SystemService;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\DependencyInjection\ContainerInterface;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  10. class DailyMaintenanceListener
  11. {
  12.     protected $request;
  13.     protected $entityManager;
  14.     protected $container;
  15.     public function __construct(RequestStack $requestStackEntityManagerInterface $entityManagerContainerInterface $container)
  16.     {
  17.         $this->request $requestStack->getCurrentRequest();
  18.         $this->entityManager $entityManager;
  19.         $this->container $container;
  20.     }
  21.     public function onKernelRequest(GetResponseEvent $event)
  22.     {
  23.         $currentDate = new \DateTime();
  24.         $startOfMaintenanceTime = new \DateTime();
  25.         $startOfMaintenanceTime->setTime(23,55,00);
  26.         $endOfMaintenanceTime = new \DateTime();
  27.         $endOfMaintenanceTime->add(new \DateInterval('P1D'));
  28.         $endOfMaintenanceTime->setTime(00,05,00);
  29.         $route $this->request->get('_route');
  30.         if ($startOfMaintenanceTime <= $currentDate && $endOfMaintenanceTime >= $currentDate) {
  31.             if (!SystemService::isAdminPath($route) && !SystemService::isIpnRoute($route)) {
  32.                 $templating $this->container->get('templating');
  33.                 $render $templating->render('@templates/Front/Shop/daily-maintenance.html.twig');
  34.                 $event->setResponse(new Response($renderResponse::HTTP_SERVICE_UNAVAILABLE));
  35.                 $event->stopPropagation();
  36.             }
  37.         }
  38.     }
  39. }