app/Customize/EventListener/LandingPageEventListener.php line 54

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\EventListener;
  13. use Customize\Service\LandingPageService;
  14. use Eccube\Request\Context;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\HttpFoundation\Cookie;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpKernel\Event\RequestEvent;
  19. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  20. use Symfony\Component\HttpKernel\KernelEvents;
  21. /**
  22.  * @inheritDoc
  23.  */
  24. class LandingPageEventListener implements EventSubscriberInterface
  25. {
  26.     /**
  27.      * @var Context
  28.      */
  29.     private $requestContext;
  30.     /**
  31.      * @var LandingPageService
  32.      */
  33.     private $landingPageService;
  34.     /**
  35.      * @inheritDoc
  36.      */
  37.     public function __construct(
  38.         Context $context,
  39.         LandingPageService $landingPageService
  40.     ) {
  41.         $this->requestContext $context;
  42.         $this->landingPageService $landingPageService;
  43.     }
  44.     public function onKernelRequest(ResponseEvent $event)
  45.     {
  46.         if ($event->isMasterRequest()) {
  47.             if ($this->requestContext->isFront()) {
  48.                 if ($this->landingPageService->isCompletePage($event->getRequest())) {
  49.                     // LPデータを削除
  50.                     $response $event->getResponse();
  51.                     $response->headers->clearCookie(LandingPageService::COOKIE_NAMELandingPageService::COOKIE_PATH);
  52.                     $event->setResponse($response);
  53.                 } else if ($this->landingPageService->isLandingPage($event->getRequest())) {
  54.                     if ($this->landingPageService->isAdvertised($event->getRequest()) || !($lp $this->landingPageService->get())) {
  55.                         //
  56.                         $land_page_data serialize($this->landingPageService->retrieveLandingPageData());
  57.                         $cookie = new Cookie(LandingPageService::COOKIE_NAME$land_page_datatime() + LandingPageService::COOKIE_EXPIRESLandingPageService::COOKIE_PATH);
  58.                         //
  59.                         $response $event->getResponse();
  60.                         $response->headers->setCookie($cookie);
  61.                         $event->setResponse($response);
  62.                     }
  63.                 }
  64.             }
  65.         }
  66.     }
  67.     /**
  68.      * @inheritDoc
  69.      */
  70.     public static function getSubscribedEvents()
  71.     {
  72.         return [
  73.             KernelEvents::RESPONSE => [
  74.                 // SecurityServiceProviderで、認証処理が完了した後に実行.
  75.                 ['onKernelRequest'6],
  76.             ],
  77.         ];
  78.     }
  79. }