<?php
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class JsonResponseFormatterListener implements EventSubscriberInterface
{
public function onKernelResponse(ResponseEvent $event): void
{
$response = $event->getResponse();
if ($response instanceof JsonResponse) {
$response->setEncodingOptions(JSON_UNESCAPED_UNICODE);
}
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::RESPONSE => 'onKernelResponse',
];
}
}