Skip to content

Instantly share code, notes, and snippets.

@mikemix
Created August 12, 2022 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemix/d3d9a8b839b6ea775a540540e1fa37e7 to your computer and use it in GitHub Desktop.
Save mikemix/d3d9a8b839b6ea775a540540e1fa37e7 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace App\User\Notification;
use App\Notification\EmailNotificationInterface;
use App\Notification\NotificationManagerInterface;
use App\Events\PostRegistrationEvent;
use App\Events\EventSubscriberInterface;
use App\User\Notification\WelcomeGreetingEmailNotificationFactory;
final class EmailNotification implements EventSubscriberInterface
{
private NotificationManagerInterface $notificationManager;
private WelcomeGreetingEmailNotificationFactory $notificationFactory;
public function __construct(
NotificationManagerInterface $notificationManager,
WelcomeGreetingEmailNotificationFactory $notificationFactory
) {
$this->notificationManager = $notificationManager;
$this->notificationFactory = $notificationFactory;
}
public static function getSubscribedEvents(): array
{
return [PostRegistrationEvent::NAME => 'sendNotification'];
}
public function sendNotification(PostRegistrationEvent $event): void
{
$notification = ($this->notificationFactory($event->getUser());
$this->notificationManager->send($notification);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment