vendor/store.shopware.com/loyxxsw6slideinbox/src/Core/Subscribers/ResponseSubscriber.php line 52

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace LoyxxSW6SlideInBox\Core\Subscribers;
  3. use Shopware\Core\System\SystemConfig\SystemConfigService;
  4. use Shopware\Storefront\Framework\Cookie\CookieProviderInterface;
  5. use Symfony\Component\DependencyInjection\ContainerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\Cookie;
  8. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  9. use Symfony\Component\HttpKernel\KernelEvents;
  10. class ResponseSubscriber implements EventSubscriberInterface
  11. {
  12.     private const PREFERENCE_COOKIE_NAME 'cookie-preference';
  13.     private const SLIDE_IN_BOX_COOKIE_NAME 'slide-in-box';
  14.     /**
  15.      * @var ContainerInterface
  16.      */
  17.     private $container;
  18.     /**
  19.      * @var CookieProviderInterface
  20.      */
  21.     private $cookieService;
  22.     /**
  23.      * @var SystemConfigService
  24.      */
  25.     private $systemConfigService;
  26.     public function __construct(
  27.         ContainerInterface $container,
  28.         CookieProviderInterface $cookieService,
  29.         SystemConfigService $systemConfigService
  30.         )
  31.     {
  32.         $this->container $container;
  33.         $this->cookieService $cookieService;
  34.         $this->systemConfigService $systemConfigService;
  35.     }
  36.     public static function getSubscribedEvents()
  37.     {
  38.         return [
  39.             KernelEvents::RESPONSE => [
  40.                 ['setResponseCache', -1800]
  41.             ]
  42.         ];
  43.     }
  44.     public function setResponseCache(ResponseEvent $event)
  45.     {
  46.         $cookies $event->getRequest()->cookies;
  47.         // slide-in-box cookie is technically required and needed to be in the header all the time
  48.         if ($cookies->get(static::SLIDE_IN_BOX_COOKIE_NAME) === null){
  49.             $event->getResponse()->headers->setCookie(new Cookie(static::SLIDE_IN_BOX_COOKIE_NAME"1"time() + (86400 30), '/'nullfalsefalse ));
  50.         }
  51.     }
  52. }