Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / http-kernel / EventListener / SurrogateListener.php
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 array(
62             KernelEvents::RESPONSE => 'onKernelResponse',
63         );
64     }
65 }