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

  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.     public function __construct(
  18.         private ?Security $security
  19.     ) {
  20.     }
  21.     public static function getSubscribedEvents()
  22.     {
  23.         return [
  24.             DomainEvent::class => ['setDomainEventUser'256],
  25.         ];
  26.     }
  27.     public function setDomainEventUser(DomainEvent $event): void
  28.     {
  29.         if (!$this->security) {
  30.             return;
  31.         }
  32.         $currentUser $this->security->getUser();
  33.         if ($currentUser instanceof UserInterface && !$event->getUser()) {
  34.             $event->setUser($currentUser);
  35.         }
  36.     }
  37. }