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

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 Enterprise License (PEL)
  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 PEL
  14.  */
  15. namespace Pimcore\Bundle\CoreBundle\EventListener;
  16. use Pimcore\Http\ResponseStack;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  19. use Symfony\Component\HttpKernel\KernelEvents;
  20. class ResponseStackListener implements EventSubscriberInterface
  21. {
  22.     /**
  23.      * @var ResponseStack
  24.      */
  25.     private $responseStack;
  26.     /**
  27.      * @param ResponseStack $responseStack
  28.      */
  29.     public function __construct(ResponseStack $responseStack)
  30.     {
  31.         $this->responseStack $responseStack;
  32.     }
  33.     /**
  34.      * @inheritDoc
  35.      */
  36.     public static function getSubscribedEvents()
  37.     {
  38.         return [
  39.             KernelEvents::RESPONSE => ['onKernelResponse'24]
  40.         ];
  41.     }
  42.     public function onKernelResponse(FilterResponseEvent $event)
  43.     {
  44.         if (!$event->isMasterRequest()) {
  45.             return;
  46.         }
  47.         if ($this->responseStack->hasResponses()) {
  48.             $event->setResponse($this->responseStack->getLastResponse());
  49.         }
  50.     }
  51. }