for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the FreshCommonApiBundle
*
* (c) Artem Henvald <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Fresh\CommonApiBundle\EventListener;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
/**
* JsonDecoderListener.
* @author Artem Henvald <[email protected]>
class JsonDecoderListener
{
/** @var array */
private const JSON_CONTENT_TYPES = [
'application/json',
];
* @param GetResponseEvent $event
public function onKernelRequest(GetResponseEvent $event): void
$request = $event->getRequest();
if ($request->headers->has('Content-Type') && \in_array($request->headers->get('Content-Type'), self::JSON_CONTENT_TYPES, true)) {
$data = \json_decode($request->getContent(), true);
if (\is_array($data)) {
$request->request = new ParameterBag($data);
}