vendor/shopware/storefront/Framework/Routing/CachedDomainLoaderInvalidator.php line 36

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Framework\Routing;
  3. use Shopware\Core\Framework\Adapter\Cache\CacheInvalidator;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenContainerEvent;
  5. use Shopware\Core\Framework\Log\Package;
  6. use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. /**
  9.  * @internal
  10.  */
  11. #[Package('storefront')]
  12. class CachedDomainLoaderInvalidator implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(private readonly CacheInvalidator $logger)
  18.     {
  19.     }
  20.     /**
  21.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  22.      */
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             EntityWrittenContainerEvent::class => [
  27.                 ['invalidate'2000],
  28.             ],
  29.         ];
  30.     }
  31.     public function invalidate(EntityWrittenContainerEvent $event): void
  32.     {
  33.         if ($event->getEventByEntityName(SalesChannelDefinition::ENTITY_NAME)) {
  34.             $this->logger->invalidate([CachedDomainLoader::CACHE_KEY]);
  35.         }
  36.     }
  37. }