<?php declare(strict_types=1);
namespace S360DeviceDetection\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Storefront\Framework\Cache\Event\HttpCacheGenerateKeyEvent;
use S360DeviceDetection\Subscriber\DeviceSubscriber;
use S360DeviceDetection\Subscriber\Mobile_Detect;
class HttpCacheGenerateKeyEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
HttpCacheGenerateKeyEvent::class => 'addCacheKey'
];
}
public function addCacheKey(HttpCacheGenerateKeyEvent $event): void
{
$device = new Mobile_Detect;
$deviceType = "";
if($device->isMobile()){
$deviceType = "mobile";
} elseif ($device->isTablet()){
$deviceType = "tablet";
} else {
$deviceType = "desktop";
}
$hash = 'md' . hash('sha256', $event->getHash() . "-" . $deviceType);
$event->setHash($hash);
}
}