vendor/shopware/core/Framework/Api/EventListener/JsonRequestTransformerListener.php line 22

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Api\EventListener;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. /**
  8.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  9.  */
  10. class JsonRequestTransformerListener implements EventSubscriberInterface
  11. {
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [
  15.             KernelEvents::REQUEST => ['onRequest'128],
  16.         ];
  17.     }
  18.     public function onRequest(RequestEvent $event): void
  19.     {
  20.         if ($event->getRequest()->getContent() && mb_stripos($event->getRequest()->headers->get('Content-Type'''), 'application/json') === 0) {
  21.             $data json_decode($event->getRequest()->getContent(), true);
  22.             if (json_last_error() !== \JSON_ERROR_NONE) {
  23.                 throw new BadRequestHttpException('The JSON payload is malformed.');
  24.             }
  25.             $event->getRequest()->request->replace(\is_array($data) ? $data : []);
  26.         }
  27.     }
  28. }