vendor/crehler/mojebambino-engine/src/Subscriber/LogoutSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. namespace Crehler\MojeBambinoEngine\Subscriber;
  3. use Shopware\Storefront\Framework\Cache\CacheResponseSubscriber;
  4. use Shopware\Storefront\Framework\Routing\Router;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. class LogoutSubscriber implements EventSubscriberInterface
  10. {
  11.     protected Router $router;
  12.     public function __construct(Router $router)
  13.     {
  14.         $this->router $router;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             KernelEvents::RESPONSE => ['onResponse', -2500]
  20.         ];
  21.     }
  22.     public function onResponse(ResponseEvent $event)
  23.     {
  24.         if ('frontend.account.logout.page' === $event->getRequest()->attributes->get('_route') && $event->getResponse() instanceof RedirectResponse) {
  25.             $loginPage $this->router->generate('frontend.account.login.page');
  26.             if ($loginPage !== $event->getResponse()->getTargetUrl()) return;
  27.             $event->setResponse(new RedirectResponse($this->router->generate('frontend.home.page')));
  28.             $event->getResponse()->headers->removeCookie(CacheResponseSubscriber::SYSTEM_STATE_COOKIE);
  29.             $event->getResponse()->headers->clearCookie(CacheResponseSubscriber::SYSTEM_STATE_COOKIE);
  30.             $event->getResponse()->headers->removeCookie(CacheResponseSubscriber::CONTEXT_CACHE_COOKIE);
  31.             $event->getResponse()->headers->clearCookie(CacheResponseSubscriber::CONTEXT_CACHE_COOKIE);
  32.         }
  33.     }
  34. }