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

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 Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\HttpKernel\Event\RequestEvent;
  16. class RequestSubscriber implements EventSubscriberInterface
  17. {
  18.     const IS_PORTAL_ENGINE_SITE 'isPortalEngineSite';
  19.     protected $portalConfigService;
  20.     protected $securityService;
  21.     public function __construct(PortalConfigService $portalConfigServiceSecurityService $securityService)
  22.     {
  23.         $this->portalConfigService $portalConfigService;
  24.         $this->securityService $securityService;
  25.     }
  26.     /**
  27.      * @return array
  28.      */
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             RequestEvent::class => ['onKernelRequest'33],
  33.         ];
  34.     }
  35.     public function onKernelRequest(RequestEvent $requestEvent)
  36.     {
  37.         if ($this->portalConfigService->isPortalEngineSite()) {
  38.             $requestEvent->getRequest()->attributes->set(self::IS_PORTAL_ENGINE_SITEtrue);
  39.         } elseif ($this->securityService->isAdminRestApiCall()) {
  40.             $requestEvent->getRequest()->attributes->set(self::IS_PORTAL_ENGINE_SITEtrue);
  41.         }
  42.     }
  43. }