src/Eccube/EventListener/RestrictFileUploadListener.php line 40

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 Eccube\EventListener;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Request\Context;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\HttpKernel\Event\RequestEvent;
  17. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  18. class RestrictFileUploadListener implements EventSubscriberInterface
  19. {
  20.     /**
  21.      * @var EccubeConfig
  22.      */
  23.     protected $eccubeConfig;
  24.     /**
  25.      * @var Context
  26.      */
  27.     protected $requestContext;
  28.     public function __construct(EccubeConfig $eccubeConfigContext $requestContext)
  29.     {
  30.         $this->eccubeConfig $eccubeConfig;
  31.         $this->requestContext $requestContext;
  32.     }
  33.     public function onKernelRequest(RequestEvent $event)
  34.     {
  35.         if (!$event->isMainRequest()) {
  36.             return;
  37.         }
  38.         if (!$this->requestContext->isAdmin()) {
  39.             return;
  40.         }
  41.         $route $event->getRequest()->attributes->get('_route');
  42.         $restrictUrls $this->eccubeConfig['eccube_restrict_file_upload_urls'];
  43.         if ($this->eccubeConfig['eccube_restrict_file_upload'] === '1' && in_array($route$restrictUrls)) {
  44.             throw new AccessDeniedHttpException(trans('exception.error_message_restrict_url'));
  45.         }
  46.     }
  47.     public static function getSubscribedEvents()
  48.     {
  49.         return [
  50.             'kernel.request' => ['onKernelRequest'7], // RouterListener より必ず後で実行する
  51.         ];
  52.     }
  53. }