vendor/sulu/headless-bundle/EventSubscriber/SnippetAreaInvalidationSubscriber.php line 46

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Sulu.
  5.  *
  6.  * (c) Sulu GmbH
  7.  *
  8.  * This source file is subject to the MIT license that is bundled
  9.  * with this source code in the file LICENSE.
  10.  */
  11. namespace Sulu\Bundle\HeadlessBundle\EventSubscriber;
  12. use Sulu\Bundle\HttpCacheBundle\Cache\CacheManager;
  13. use Sulu\Bundle\SnippetBundle\Domain\Event\WebspaceDefaultSnippetModifiedEvent;
  14. use Sulu\Bundle\SnippetBundle\Domain\Event\WebspaceDefaultSnippetRemovedEvent;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. /**
  17.  * @final
  18.  *
  19.  * @internal
  20.  */
  21. class SnippetAreaInvalidationSubscriber implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * @var CacheManager|null
  25.      */
  26.     private $cacheManager;
  27.     public function __construct(?CacheManager $cacheManager)
  28.     {
  29.         $this->cacheManager $cacheManager;
  30.     }
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             WebspaceDefaultSnippetModifiedEvent::class => 'invalidateSnippetAreaOnModified',
  35.             WebspaceDefaultSnippetRemovedEvent::class => 'invalidateSnippetAreaOnRemoved',
  36.         ];
  37.     }
  38.     public function invalidateSnippetAreaOnModified(WebspaceDefaultSnippetModifiedEvent $event): void
  39.     {
  40.         $this->invalidateSnippetArea($event->getSnippetAreaKey());
  41.     }
  42.     public function invalidateSnippetAreaOnRemoved(WebspaceDefaultSnippetRemovedEvent $event): void
  43.     {
  44.         $this->invalidateSnippetArea($event->getSnippetAreaKey());
  45.     }
  46.     private function invalidateSnippetArea(string $snippetAreaKey): void
  47.     {
  48.         if (!$this->cacheManager) {
  49.             return;
  50.         }
  51.         $this->cacheManager->invalidateReference('snippet_area'$snippetAreaKey);
  52.     }
  53. }