Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / http-kernel / EventListener / SurrogateListener.php
index dc815a216f6c00cb920c2690d57982c76fb3930f..37d1b9d04eaad56233528c35e5bd7a5e0bbb3843 100644 (file)
@@ -12,6 +12,7 @@
 namespace Symfony\Component\HttpKernel\EventListener;
 
 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
+use Symfony\Component\HttpKernel\HttpCache\HttpCache;
 use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface;
 use Symfony\Component\HttpKernel\KernelEvents;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -25,11 +26,6 @@ class SurrogateListener implements EventSubscriberInterface
 {
     private $surrogate;
 
-    /**
-     * Constructor.
-     *
-     * @param SurrogateInterface $surrogate An SurrogateInterface instance
-     */
     public function __construct(SurrogateInterface $surrogate = null)
     {
         $this->surrogate = $surrogate;
@@ -37,16 +33,27 @@ class SurrogateListener implements EventSubscriberInterface
 
     /**
      * Filters the Response.
-     *
-     * @param FilterResponseEvent $event A FilterResponseEvent instance
      */
     public function onKernelResponse(FilterResponseEvent $event)
     {
-        if (!$event->isMasterRequest() || null === $this->surrogate) {
+        if (!$event->isMasterRequest()) {
+            return;
+        }
+
+        $kernel = $event->getKernel();
+        $surrogate = $this->surrogate;
+        if ($kernel instanceof HttpCache) {
+            $surrogate = $kernel->getSurrogate();
+            if (null !== $this->surrogate && $this->surrogate->getName() !== $surrogate->getName()) {
+                $surrogate = $this->surrogate;
+            }
+        }
+
+        if (null === $surrogate) {
             return;
         }
 
-        $this->surrogate->addSurrogateControl($event->getResponse());
+        $surrogate->addSurrogateControl($event->getResponse());
     }
 
     public static function getSubscribedEvents()