<?php
/*
* Created on Fri Dec 02 2022
*
* DAVID-OLIVIER DESCOMBES
*
* @licence
* You may not sell, sub-license, rent or lease any portion of the Software or Documentation to anyone.
*
* Copyright (c) 2022 dodarchitecte.com (https://dodarchitecte.com)
*
* Developed by developpeur-informatique.ma (https://www.developpeur-informatique.ma)
*/
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Event\LogoutEvent;
class LogoutSubscriber implements EventSubscriberInterface
{
public function onLogoutEvent(LogoutEvent $event)
{
if (in_array('application/json', $event->getRequest()->getAcceptableContentTypes(), true)) {
$event->setResponse(new JsonResponse(null, Response::HTTP_NO_CONTENT));
}
}
public static function getSubscribedEvents(): array
{
return [
LogoutEvent::class => 'onLogoutEvent',
];
}
}