vendor/symfony/http-kernel/EventListener/SurrogateListener.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpKernel\EventListener;
  11. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  12. use Symfony\Component\HttpKernel\HttpCache\HttpCache;
  13. use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. /**
  17.  * SurrogateListener adds a Surrogate-Control HTTP header when the Response needs to be parsed for Surrogates.
  18.  *
  19.  * @author Fabien Potencier <fabien@symfony.com>
  20.  */
  21. class SurrogateListener implements EventSubscriberInterface
  22. {
  23.     private $surrogate;
  24.     public function __construct(SurrogateInterface $surrogate null)
  25.     {
  26.         $this->surrogate $surrogate;
  27.     }
  28.     /**
  29.      * Filters the Response.
  30.      */
  31.     public function onKernelResponse(FilterResponseEvent $event)
  32.     {
  33.         if (!$event->isMasterRequest()) {
  34.             return;
  35.         }
  36.         $kernel $event->getKernel();
  37.         $surrogate $this->surrogate;
  38.         if ($kernel instanceof HttpCache) {
  39.             $surrogate $kernel->getSurrogate();
  40.             if (null !== $this->surrogate && $this->surrogate->getName() !== $surrogate->getName()) {
  41.                 $surrogate $this->surrogate;
  42.             }
  43.         }
  44.         if (null === $surrogate) {
  45.             return;
  46.         }
  47.         $surrogate->addSurrogateControl($event->getResponse());
  48.     }
  49.     public static function getSubscribedEvents()
  50.     {
  51.         return array(
  52.             KernelEvents::RESPONSE => 'onKernelResponse',
  53.         );
  54.     }
  55. }