src/EventSubscriber/CommentBanSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\Account\Customer;
  4. use App\Entity\User;
  5. use App\Service\CustomerBanService;
  6. use Carbon\CarbonImmutable;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. use Symfony\Component\Security\Core\Security;
  10. class CommentBanSubscriber implements EventSubscriberInterface
  11. {
  12.     public function __construct(
  13.         private Security $security,
  14.         private CustomerBanService $customerBanService
  15.     ) {}
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             KernelEvents::REQUEST => 'removeCommentBan',
  20.         ];
  21.     }
  22.     public function removeCommentBan(): void
  23.     {
  24.         /** @var User $user */
  25.         $user $this->security->getUser();
  26.         if($user && $user instanceof Customer && $user->getCommentBan() && $user->getCommentBan()->getEndsAt() <= CarbonImmutable::now()) {
  27.             $this->customerBanService->unbanCommentBan($user);
  28.         }
  29.     }
  30. }