custom/plugins/S360ListingViewSwitch/src/Storefront/Subscriber/HttpCacheGenerateKeyEventSubscriber.php line 23

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace S360ListingViewSwitch\Storefront\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Storefront\Framework\Cache\Event\HttpCacheGenerateKeyEvent;
  5. use S360ListingViewSwitch\S360ListingViewSwitch;
  6. class HttpCacheGenerateKeyEventSubscriber implements EventSubscriberInterface
  7. {
  8.     
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             HttpCacheGenerateKeyEvent::class => 'addCacheKey'
  13.         ];
  14.     }
  15.     /**
  16.      * if cookie is set and value is valid, cache key gets decorated
  17.      * one cannot access session in here, not started yet and would cause conflict if started here
  18.      */
  19.     public function addCacheKey(HttpCacheGenerateKeyEvent $event): void
  20.     {
  21.         // default, TODO: replace with default value
  22.         $listingMode "gallery";
  23.         
  24.         if(isset($_COOKIE[S360ListingViewSwitch::COOKIE_KEY])){
  25.             if(in_array($_COOKIE[S360ListingViewSwitch::COOKIE_KEY], S360ListingViewSwitch::AVAILABLE_VIEWS)){
  26.                 $listingMode $_COOKIE[S360ListingViewSwitch::COOKIE_KEY];
  27.             }
  28.         } 
  29.         
  30.         $hash 'md' hash('sha256'$event->getHash() . "-" $listingMode);
  31.         $event->setHash($hash);
  32.     }
  33. }