src/EventListener/AprilFoolsListener.php line 27

Open in your IDE?
  1. <?php
  2. // src/EventListener/RequestListener.php
  3. namespace App\EventListener;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  7. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  8. use Symfony\Component\Security\Core\Security;
  9. use App\Service\ConfigService;
  10. use App\Entity\KycVerificationStatus;
  11. class AprilFoolsListener
  12. {
  13.     private $urlGenerator;
  14.     private $authorizationChecker;
  15.     private $security;
  16.     public function __construct(UrlGeneratorInterface $urlGeneratorAuthorizationCheckerInterface $authorizationCheckerSecurity $security, private ConfigService $configService)
  17.     {
  18.         $this->urlGenerator $urlGenerator;
  19.         $this->authorizationChecker $authorizationChecker;
  20.         $this->security $security;
  21.     }
  22.     public function onKernelRequest(RequestEvent $event)
  23.     {
  24.         $request $event->getRequest();
  25.         $url $this->urlGenerator->generate('app_important_infos');
  26.         // Check if the user is authenticated and has the 'ROLE_CLIENT'
  27.         $isInfosPage strncmp($request->getPathInfo(), $urlstrlen($url)) == 0;
  28.         if ($this->authorizationChecker->isGranted('APRIL_FOOLS')) { 
  29.             if(!$isInfosPage)   {
  30.                 $response = new RedirectResponse($url);
  31.                 $event->setResponse($response);
  32.             }
  33.         } else if($isInfosPage){
  34.             $response = new RedirectResponse($this->urlGenerator->generate('app_client_dahsboard'));
  35.             $event->setResponse($response);
  36.         }
  37.                 
  38.     }
  39.     
  40. }