vendor/pimcore/portal-engine/src/EventSubscriber/RequestSubscriber.php line 45

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\PortalEngineBundle\EventSubscriber;
  12. use Pimcore\Bundle\PortalEngineBundle\Service\PortalConfig\PortalConfigService;
  13. use Pimcore\Bundle\PortalEngineBundle\Service\Security\SecurityService;
  14. use Pimcore\Tool;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\HttpKernel\Event\RequestEvent;
  17. class RequestSubscriber implements EventSubscriberInterface
  18. {
  19.     const IS_PORTAL_ENGINE_SITE 'isPortalEngineSite';
  20.     protected $portalConfigService;
  21.     protected $securityService;
  22.     public function __construct(PortalConfigService $portalConfigServiceSecurityService $securityService)
  23.     {
  24.         $this->portalConfigService $portalConfigService;
  25.         $this->securityService $securityService;
  26.     }
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return [
  30.             RequestEvent::class => ['onKernelRequest'33],
  31.         ];
  32.     }
  33.     public function onKernelRequest(RequestEvent $requestEvent)
  34.     {
  35.         if ($this->portalConfigService->isPortalEngineSite() || Tool::isFrontendRequestByAdmin()) {
  36.             $requestEvent->getRequest()->attributes->set(self::IS_PORTAL_ENGINE_SITEtrue);
  37.         } elseif ($this->securityService->isAdminRestApiCall()) {
  38.             $requestEvent->getRequest()->attributes->set(self::IS_PORTAL_ENGINE_SITEtrue);
  39.         }
  40.     }
  41. }