custom/plugins/ZeobvPwaStorefront/src/Subscriber/EntitySubscriber.php line 52

Open in your IDE?
  1. <?php
  2. namespace Zeobv\PwaStorefront\Subscriber;
  3. use Psr\Log\LoggerInterface;
  4. use Shopware\Core\Content\Category\CategoryEvents;
  5. use Shopware\Core\Content\Cms\CmsPageEvents;
  6. use Shopware\Core\Content\Product\ProductEvents;
  7. use Shopware\Core\System\SalesChannel\SalesChannelEvents;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Zeobv\PwaStorefront\Services\ConfigService;
  10. class EntitySubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var ConfigService
  14.      */
  15.     protected $configService;
  16.     /**
  17.      * @var LoggerInterface
  18.      */
  19.     protected $logger;
  20.     /**
  21.      * @param ConfigService   $configService
  22.      * @param LoggerInterface $logger
  23.      */
  24.     public function __construct(
  25.         ConfigService $configService,
  26.         LoggerInterface $logger
  27.     )
  28.     {
  29.         $this->configService $configService;
  30.         $this->logger $logger;
  31.     }
  32.     /**
  33.      * @return string[]
  34.      */
  35.     public static function getSubscribedEvents(): array
  36.     {
  37.         return [
  38.             CmsPageEvents::PAGE_WRITTEN_EVENT => 'afterEntityWritten',
  39.             ProductEvents::PRODUCT_WRITTEN_EVENT => 'afterEntityWritten',
  40.             ProductEvents::PRODUCT_CATEGORY_WRITTEN_EVENT => 'afterEntityWritten',
  41.             CategoryEvents::CATEGORY_WRITTEN_EVENT => 'afterEntityWritten',
  42.             SalesChannelEvents::SALES_CHANNEL_WRITTEN => 'afterEntityWritten',
  43.         ];
  44.     }
  45.     public function afterEntityWritten(): void
  46.     {
  47.         try {
  48.             $this->configService->refreshCacheName();
  49.         } catch (\Throwable $e) {
  50.             $this->logger->error($e->getMessage(), ['trace' => $e->getTraceAsString()]);
  51.         }
  52.     }
  53. }