vendor/ibexa/http-cache/src/lib/EventSubscriber/HttpCacheResponseSubscriber.php line 42

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. namespace Ibexa\HttpCache\EventSubscriber;
  7. use Ibexa\Contracts\HttpCache\ResponseTagger\ResponseTagger;
  8. use Ibexa\Core\MVC\Symfony\View\CachableView;
  9. use Ibexa\HttpCache\ResponseConfigurator\ResponseCacheConfigurator;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  12. use Symfony\Component\HttpKernel\KernelEvents;
  13. /**
  14.  * Configures the Response HTTP cache properties.
  15.  */
  16. class HttpCacheResponseSubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var \Ibexa\Contracts\HttpCache\ResponseTagger\ResponseTagger
  20.      */
  21.     private $dispatcherTagger;
  22.     /**
  23.      * @var \Ibexa\HttpCache\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(ResponseEvent $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. }
  48. class_alias(HttpCacheResponseSubscriber::class, 'EzSystems\PlatformHttpCacheBundle\EventSubscriber\HttpCacheResponseSubscriber');