[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/symfony/http-kernel/EventListener/ -> SurrogateListener.php (source)

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


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1