<?php
declare(strict_types=1);
namespace Harmonizely\EventListener;
use Harmonizely\EmailManager\EventEmailManagerInterface;
use Harmonizely\Mailer\AllowedSendingEmailNotificationToInviteePolicy;
use Harmonizely\Model\EventInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Webmozart\Assert\Assert;
final class ParticipantInvitedListener
{
/**
* @var EventEmailManagerInterface
*/
private $eventEmailManager;
private AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy;
public function __construct(
EventEmailManagerInterface $eventEmailManager,
AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy
)
{
$this->eventEmailManager = $eventEmailManager;
$this->allowedSendingEmailNotificationToInviteePolicy = $allowedSendingEmailNotificationToInviteePolicy;
}
public function sendInvitationNotifyToParticipants(GenericEvent $event): void
{
$participantsEmails = $event->getArgument('emails');
$message = $event->getArgument('message');
$inviter = $event->getArgument('inviter');
/** @var EventInterface $event */
$event = $event->getSubject();
Assert::isInstanceOf($event, EventInterface::class);
if (false === ($this->allowedSendingEmailNotificationToInviteePolicy)($event)) {
return;
}
$this->eventEmailManager->sendInvitationNotifyToParticipants($event, $participantsEmails, $inviter, $message);
}
}