custom/plugins/s360-device-detection/src/Subscriber/HttpCacheGenerateKeyEventSubscriber.php line 20

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace S360DeviceDetection\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Storefront\Framework\Cache\Event\HttpCacheGenerateKeyEvent;
  5. use S360DeviceDetection\Subscriber\DeviceSubscriber;
  6. use S360DeviceDetection\Subscriber\Mobile_Detect;
  7. class HttpCacheGenerateKeyEventSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             HttpCacheGenerateKeyEvent::class => 'addCacheKey'
  13.         ];
  14.     }
  15.     public function addCacheKey(HttpCacheGenerateKeyEvent $event): void
  16.     {
  17.         $device = new Mobile_Detect;
  18.         $deviceType "";
  19.         if($device->isMobile()){
  20.             $deviceType "mobile";
  21.         } elseif ($device->isTablet()){
  22.             $deviceType "tablet";
  23.         } else {
  24.             $deviceType "desktop";
  25.         }
  26.         $hash 'md' hash('sha256'$event->getHash() . "-" $deviceType);
  27.         $event->setHash($hash);
  28.     }
  29. }