src/EventListener/JsonResponseFormatterListener.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class JsonResponseFormatterListener implements EventSubscriberInterface
  8. {
  9.     public function onKernelResponse(ResponseEvent $event): void
  10.     {
  11.         $response $event->getResponse();
  12.         if ($response instanceof JsonResponse) {
  13.             $response->setEncodingOptions(JSON_UNESCAPED_UNICODE);
  14.         }
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             KernelEvents::RESPONSE => 'onKernelResponse',
  20.         ];
  21.     }
  22. }