vendor/pimcore/pimcore/bundles/CoreBundle/EventListener/ResponseStackListener.php line 47

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Commercial License (PCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  14.  */
  15. namespace Pimcore\Bundle\CoreBundle\EventListener;
  16. use Pimcore\Http\ResponseStack;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  19. use Symfony\Component\HttpKernel\KernelEvents;
  20. /**
  21.  * @internal
  22.  */
  23. class ResponseStackListener implements EventSubscriberInterface
  24. {
  25.     /**
  26.      * @param ResponseStack $responseStack
  27.      */
  28.     public function __construct(private ResponseStack $responseStack)
  29.     {
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public static function getSubscribedEvents()
  35.     {
  36.         return [
  37.             KernelEvents::RESPONSE => ['onKernelResponse'24],
  38.         ];
  39.     }
  40.     public function onKernelResponse(ResponseEvent $event)
  41.     {
  42.         if (!$event->isMainRequest()) {
  43.             return;
  44.         }
  45.         if ($this->responseStack->hasResponses()) {
  46.             $event->setResponse($this->responseStack->getLastResponse());
  47.         }
  48.     }
  49. }