<?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 NewEventScheduledListener
{
private $eventEmailManager;
private AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy;
public function __construct(
EventEmailManagerInterface $eventEmailManager,
AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy
) {
$this->eventEmailManager = $eventEmailManager;
$this->allowedSendingEmailNotificationToInviteePolicy = $allowedSendingEmailNotificationToInviteePolicy;
}
public function sendEmail(GenericEvent $event): void
{
/** @var EventInterface $event */
$event = $event->getSubject();
Assert::isInstanceOf($event, EventInterface::class);
if (false === ($this->allowedSendingEmailNotificationToInviteePolicy)($event)) {
return;
}
$this->eventEmailManager->sendNewEventInviteeConfirmation($event);
}
public function sendNewEventEmailConfirmation(GenericEvent $event): void
{
/** @var EventInterface $event */
$event = $event->getSubject();
Assert::isInstanceOf($event, EventInterface::class);
$this->eventEmailManager->sendNewEventEmailConfirmation($event);
}
}