<?php declare(strict_types=1);
/*
* (c) webpiloten. <kontakt@web-piloten.de>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Spno\NewsletterEconomy\Subscriber;
use Spno\NewsletterEconomy\Event\NewsletterDispatcherExceptionEvent;
use Spno\NewsletterEconomy\Service\Newsletter\NewsletterStatistics;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class NewsletterDispatcherSubscriber implements EventSubscriberInterface
{
private NewsletterStatistics $newsletterStatistics;
public function __construct(NewsletterStatistics $newsletterStatistics)
{
$this->newsletterStatistics = $newsletterStatistics;
}
public static function getSubscribedEvents(): array
{
return [
NewsletterDispatcherExceptionEvent::class => 'onNewsletterDispatcherException',
];
}
public function onNewsletterDispatcherException(NewsletterDispatcherExceptionEvent $event): void
{
$newsletter = $event->getNewsletter();
$recipient = $event->getRecipient();
$this->newsletterStatistics->createRecipientFailed(
$newsletter->getId(),
$recipient->getId()
);
}
}