vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/EventListener/AdminSectionCacheControlSubscriber.php line 41

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\AdminBundle\EventListener;
  12. use Sylius\Bundle\AdminBundle\SectionResolver\AdminSection;
  13. use Sylius\Bundle\CoreBundle\SectionResolver\SectionProviderInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  16. use Symfony\Component\HttpKernel\KernelEvents;
  17. final class AdminSectionCacheControlSubscriber implements EventSubscriberInterface
  18. {
  19.     /** @var SectionProviderInterface */
  20.     private $sectionProvider;
  21.     public function __construct(SectionProviderInterface $sectionProvider)
  22.     {
  23.         $this->sectionProvider $sectionProvider;
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             KernelEvents::RESPONSE => 'setCacheControlDirectives',
  29.         ];
  30.     }
  31.     public function setCacheControlDirectives(ResponseEvent $event): void
  32.     {
  33.         if (!$this->sectionProvider->getSection() instanceof AdminSection) {
  34.             return;
  35.         }
  36.         $response $event->getResponse();
  37.         $response->headers->addCacheControlDirective('no-cache'true);
  38.         $response->headers->addCacheControlDirective('max-age''0');
  39.         $response->headers->addCacheControlDirective('must-revalidate'true);
  40.         $response->headers->addCacheControlDirective('no-store'true);
  41.     }
  42. }