vendor/sulu/sulu/src/Sulu/Bundle/SecurityBundle/EventListener/SystemListener.php line 54

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\SecurityBundle\EventListener;
  11. use Sulu\Bundle\AdminBundle\Admin\Admin;
  12. use Sulu\Bundle\SecurityBundle\System\SystemStoreInterface;
  13. use Sulu\Component\DocumentManager\Subscriber\EventSubscriberInterface;
  14. use Sulu\Component\HttpKernel\SuluKernel;
  15. use Sulu\Component\Webspace\Analyzer\RequestAnalyzerInterface;
  16. use Symfony\Component\HttpKernel\Event\RequestEvent;
  17. use Symfony\Component\HttpKernel\KernelEvents;
  18. class SystemListener implements EventSubscriberInterface
  19. {
  20.     /**
  21.      * @var SystemStoreInterface
  22.      */
  23.     private $systemStore;
  24.     /**
  25.      * @var RequestAnalyzerInterface
  26.      */
  27.     private $requestAnalyzer;
  28.     /**
  29.      * @var string
  30.      */
  31.     private $context;
  32.     public function __construct(
  33.         SystemStoreInterface $systemStore,
  34.         RequestAnalyzerInterface $requestAnalyzer,
  35.         string $context
  36.     ) {
  37.         $this->systemStore $systemStore;
  38.         $this->requestAnalyzer $requestAnalyzer;
  39.         $this->context $context;
  40.     }
  41.     public static function getSubscribedEvents(): array
  42.     {
  43.         return [KernelEvents::REQUEST => ['onKernelRequest'24]];
  44.     }
  45.     public function onKernelRequest(RequestEvent $requestEvent)
  46.     {
  47.         if (SuluKernel::CONTEXT_ADMIN === $this->context) {
  48.             $this->systemStore->setSystem(Admin::SULU_ADMIN_SECURITY_SYSTEM);
  49.             return;
  50.         }
  51.         $webspace $this->requestAnalyzer->getWebspace();
  52.         if ($webspace) {
  53.             $security $webspace->getSecurity();
  54.             if ($security) {
  55.                 $this->systemStore->setSystem($security->getSystem());
  56.                 return;
  57.             }
  58.         }
  59.     }
  60. }