src/EventListener/RewardListener.php line 26

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. class RewardListener
  11. {
  12.     private $urlGenerator;
  13.     private $authorizationChecker;
  14.     private $security;
  15.     public function __construct(UrlGeneratorInterface $urlGeneratorAuthorizationCheckerInterface $authorizationCheckerSecurity $security, private ConfigService $configService)
  16.     {
  17.         $this->urlGenerator $urlGenerator;
  18.         $this->authorizationChecker $authorizationChecker;
  19.         $this->security $security;
  20.     }
  21.     public function onKernelRequest(RequestEvent $event)
  22.     {
  23.         $request $event->getRequest();
  24.      
  25.         $user $this->security->getUser();
  26.         
  27.         $excludePaths = [$this->urlGenerator->generate('app_choose_reward'),$this->urlGenerator->generate('app_select_chosen_reward')];
  28.         foreach($excludePaths as $path){
  29.             if(strncmp($request->getPathInfo(), $pathstrlen($path)) == 0){
  30.                 return;
  31.             }
  32.         } 
  33.         $url $this->urlGenerator->generate('app_choose_reward');
  34.         if($user && $user->getWaitingUserRankingRewardChoice() && strncmp($request->getPathInfo(), $urlstrlen($url)) != ){
  35.             $event->setResponse(new RedirectResponse($url));
  36.         }
  37.         
  38.     }
  39.     
  40. }