app/Plugin/Schedule/EventSubscriber/UserPageEventSubscriber.php line 46

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2018 SYSTEM_KD
  4.  * Date: 2018/12/09
  5.  */
  6. namespace Plugin\Schedule\EventSubscriber;
  7. use Eccube\Controller\Admin\Content\FileController;
  8. use Eccube\Entity\Page;
  9. use Eccube\Repository\PageRepository;
  10. use Plugin\Schedule\Service\ScheduleService;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  13. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  14. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  15. use Symfony\Component\HttpKernel\KernelEvents;
  16. class UserPageEventSubscriber extends EventSubscriberBase implements EventSubscriberInterface
  17. {
  18.     private $pageRepository;
  19.     private $scheduleService;
  20.     public function __construct(
  21.         PageRepository $pageRepository,
  22.         ScheduleService $scheduleService,
  23.         SessionInterface $session
  24.     )
  25.     {
  26.         parent::__construct($session);
  27.         $this->pageRepository $pageRepository;
  28.         $this->scheduleService $scheduleService;
  29.         $this->session $session;
  30.     }
  31.     /**
  32.      * ユーザ作成ページコントロール前
  33.      *
  34.      * @param FilterControllerEvent $event
  35.      * @throws \Exception
  36.      */
  37.     public function onUserDataController(FilterControllerEvent $event)
  38.     {
  39.         if ($this->isAdminUser()) {
  40.             return;
  41.         }
  42.         $request $event->getRequest();
  43.         $route $request->attributes->get('_route');
  44.         if ($route == "user_data") {
  45.             $detail $request->get('route');
  46.             /** @var Page $page */
  47.             $page $this->pageRepository->findOneBy(
  48.                 [
  49.                     'url' => $detail,
  50.                     'edit_type' => Page::EDIT_TYPE_USER,
  51.                 ]
  52.             );
  53.             if (null !== $page) {
  54.                 // 公開日時チェック
  55.                 if (!$this->scheduleService->isActiveTimePage($page)) {
  56.                     throw new NotFoundHttpException();
  57.                 }
  58.             }
  59.         }
  60.     }
  61.     /**
  62.      * Returns an array of event names this subscriber wants to listen to.
  63.      *
  64.      * The array keys are event names and the value can be:
  65.      *
  66.      * * The method name to call (priority defaults to 0)
  67.      * * An array composed of the method name to call and the priority
  68.      * * An array of arrays composed of the method names to call and respective
  69.      *   priorities, or 0 if unset
  70.      *
  71.      * For instance:
  72.      *
  73.      * * array('eventName' => 'methodName')
  74.      * * array('eventName' => array('methodName', $priority))
  75.      * * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
  76.      *
  77.      * @return array The event names to listen to
  78.      */
  79.     public static function getSubscribedEvents()
  80.     {
  81.         return [
  82.             KernelEvents::CONTROLLER => [
  83.                 'onUserDataController'
  84.             ],
  85.         ];
  86.     }
  87. }