src/EventListener/ParticipantInvitedListener.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Harmonizely\EventListener;
  4. use Harmonizely\EmailManager\EventEmailManagerInterface;
  5. use Harmonizely\Mailer\AllowedSendingEmailNotificationToInviteePolicy;
  6. use Harmonizely\Model\EventInterface;
  7. use Symfony\Component\EventDispatcher\GenericEvent;
  8. use Webmozart\Assert\Assert;
  9. final class ParticipantInvitedListener
  10. {
  11.     /**
  12.      * @var EventEmailManagerInterface
  13.      */
  14.     private $eventEmailManager;
  15.     private AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy;
  16.     public function __construct(
  17.         EventEmailManagerInterface $eventEmailManager,
  18.         AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy
  19.     )
  20.     {
  21.         $this->eventEmailManager $eventEmailManager;
  22.         $this->allowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy;
  23.     }
  24.     public function sendInvitationNotifyToParticipants(GenericEvent $event): void
  25.     {
  26.         $participantsEmails $event->getArgument('emails');
  27.         $message $event->getArgument('message');
  28.         $inviter $event->getArgument('inviter');
  29.         $showScheduledAtList $event->hasArgument('showScheduledAtList') && $event->getArgument('showScheduledAtList');
  30.         /** @var EventInterface $event */
  31.         $event $event->getSubject();
  32.         Assert::isInstanceOf($eventEventInterface::class);
  33.         if (false === ($this->allowedSendingEmailNotificationToInviteePolicy)($event)) {
  34.             return;
  35.         }
  36.         $this->eventEmailManager->sendInvitationNotifyToParticipants(
  37.             $event,
  38.             $participantsEmails,
  39.             $inviter,
  40.             $message,
  41.             $showScheduledAtList
  42.         );
  43.     }
  44. }