vendor/shopware/core/System/SalesChannel/Api/StoreApiResponseListener.php line 35

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\System\SalesChannel\Api;
  3. use Shopware\Core\Framework\Log\Package;
  4. use Shopware\Core\System\SalesChannel\StoreApiResponse;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. /**
  10.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  11.  */
  12. #[Package('core')]
  13. class StoreApiResponseListener implements EventSubscriberInterface
  14. {
  15.     private StructEncoder $encoder;
  16.     /**
  17.      * @internal
  18.      */
  19.     public function __construct(StructEncoder $encoder)
  20.     {
  21.         $this->encoder $encoder;
  22.     }
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             KernelEvents::RESPONSE => ['encodeResponse'10000],
  27.         ];
  28.     }
  29.     public function encodeResponse(ResponseEvent $event): void
  30.     {
  31.         $response $event->getResponse();
  32.         if (!$response instanceof StoreApiResponse) {
  33.             return;
  34.         }
  35.         $fields = new ResponseFields(
  36.             $event->getRequest()->get('includes', [])
  37.         );
  38.         $encoded $this->encoder->encode($response->getObject(), $fields);
  39.         $event->setResponse(new JsonResponse($encoded$response->getStatusCode(), $response->headers->all()));
  40.     }
  41. }