Created
August 12, 2022 14:35
-
-
Save mikemix/d3d9a8b839b6ea775a540540e1fa37e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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