src/EventSubscriber/LogoutSubscriber.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use JetBrains\PhpStorm\ArrayShape;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Security\Http\Event\LogoutEvent;
  8. class LogoutSubscriber implements EventSubscriberInterface
  9. {
  10.     public function onLogoutEvent(LogoutEvent $event): void
  11.     {
  12.          if (in_array('application/json'$event->getRequest()->getAcceptableContentTypes(), true)){
  13.             $event->setResponse(new JsonResponse(nullResponse::HTTP_NO_CONTENT));
  14.         }
  15.     }
  16.     #[ArrayShape([LogoutEvent::class => "string"])] public static function
  17.     getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             LogoutEvent::class => 'onLogoutEvent',
  21.         ];
  22.     }
  23. }