vendor/ezsystems/ezplatform-http-cache/src/EventSubscriber/HttpCacheResponseSubscriber.php line 42

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. namespace EzSystems\PlatformHttpCacheBundle\EventSubscriber;
  7. use EzSystems\PlatformHttpCacheBundle\ResponseConfigurator\ResponseCacheConfigurator;
  8. use EzSystems\PlatformHttpCacheBundle\ResponseTagger\ResponseTagger;
  9. use eZ\Publish\Core\MVC\Symfony\View\CachableView;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  12. use Symfony\Component\HttpKernel\KernelEvents;
  13. /**
  14.  * Configures the Response HTTP cache properties.
  15.  */
  16. class HttpCacheResponseSubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var \EzSystems\PlatformHttpCacheBundle\ResponseTagger\ResponseTagger
  20.      */
  21.     private $dispatcherTagger;
  22.     /**
  23.      * @var \EzSystems\PlatformHttpCacheBundle\ResponseConfigurator\ResponseCacheConfigurator
  24.      */
  25.     private $responseConfigurator;
  26.     public function __construct(ResponseCacheConfigurator $responseConfiguratorResponseTagger $dispatcherTagger)
  27.     {
  28.         $this->responseConfigurator $responseConfigurator;
  29.         $this->dispatcherTagger $dispatcherTagger;
  30.     }
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [KernelEvents::RESPONSE => ['configureCache'10]];
  34.     }
  35.     public function configureCache(FilterResponseEvent $event)
  36.     {
  37.         $view $event->getRequest()->attributes->get('view');
  38.         if (!$view instanceof CachableView || !$view->isCacheEnabled()) {
  39.             return;
  40.         }
  41.         $response $event->getResponse();
  42.         $this->responseConfigurator->enableCache($response);
  43.         $this->responseConfigurator->setSharedMaxAge($response);
  44.         $this->dispatcherTagger->tag($view);
  45.         // NB!: FOSHTTPCacheBundle is taking care about writing the tags in own tag handler happening with priority 0
  46.     }
  47. }