custom/plugins/AcrisCookieConsentCS/src/Subscriber/NotFoundCacheKeySubscriber.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\CookieConsent\Subscriber;
  3. use Shopware\Storefront\Framework\Routing\NotFound\NotFoundPageCacheKeyEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpFoundation\ParameterBag;
  6. class NotFoundCacheKeySubscriber implements EventSubscriberInterface
  7. {
  8.     public static function getSubscribedEvents()
  9.     {
  10.         // we don't want to get the event name by ::class because of event did not exist before 6.4.15.0.
  11.         return [
  12.             'Shopware\Storefront\Framework\Routing\NotFound\NotFoundPageCacheKeyEvent' => 'onNotFoundPageCacheKeyEvent'
  13.         ];
  14.     }
  15.     public function onNotFoundPageCacheKeyEvent(NotFoundPageCacheKeyEvent $notFoundPageCacheKeyEvent): void
  16.     {
  17.         if($notFoundPageCacheKeyEvent->getRequest()->cookies instanceof ParameterBag && !empty($notFoundPageCacheKeyEvent->getRequest()->cookies->all()) && !empty($notFoundPageCacheKeyEvent->getKey()) && is_string($notFoundPageCacheKeyEvent->getKey()) && is_array($notFoundPageCacheKeyEvent->getRequest()->cookies->all())) {
  18.             $key json_encode($notFoundPageCacheKeyEvent->getRequest()->cookies->all());
  19.             if (empty($key)) return;
  20.             $hashKey md5($key);
  21.             if (empty($hashKey)) return;
  22.             $notFoundPageCacheKeyEvent->setKey($notFoundPageCacheKeyEvent->getKey() . $hashKey);
  23.         }
  24.     }
  25. }