vendor/sulu/sulu/src/Sulu/Bundle/ActivityBundle/Application/Subscriber/SetDomainEventUserSubscriber.php line 39

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\ActivityBundle\Application\Subscriber;
  11. use Sulu\Bundle\ActivityBundle\Domain\Event\DomainEvent;
  12. use Sulu\Component\Security\Authentication\UserInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\Security\Core\Security;
  15. class SetDomainEventUserSubscriber implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var Security|null
  19.      */
  20.     private $security;
  21.     public function __construct(
  22.         ?Security $security
  23.     ) {
  24.         $this->security $security;
  25.     }
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.             DomainEvent::class => ['setDomainEventUser'256],
  30.         ];
  31.     }
  32.     public function setDomainEventUser(DomainEvent $event): void
  33.     {
  34.         if (!$this->security) {
  35.             return;
  36.         }
  37.         $currentUser $this->security->getUser();
  38.         if ($currentUser instanceof UserInterface && !$event->getUser()) {
  39.             $event->setUser($currentUser);
  40.         }
  41.     }
  42. }