Last active
August 26, 2022 18:44
-
-
Save mikemix/d7dc0a9c2c3bcdab6b7538d34c5c3c0e 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\User\Notification\WelcomeGreetingEmailNotificationFactory; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
final class EmailNotification implements EventSubscriberInterface | |
{ | |
private NotificationManagerInterface $notificationManager; | |
private WelcomeGreetingEmailNotificationFactory $notificationFactory; | |
public function __construct( | |
NotificationManagerInterface $notificationManager, | |
WelcomeGreetingEmailNotificationFactory $notificationFactory | |
) { | |
$this->notificationManager = $notificationManager; | |
$this->notificationFactory = $notificationFactory; | |
} | |
/** {@inheritDoc} */ | |
public static function getSubscribedEvents(): array | |
{ | |
return [PostRegistrationEvent::NAME => 'sendNotification']; | |
} | |
public function sendNotification(PostRegistrationEvent $event): void | |
{ | |
$notification = ($this->notificationFactory($event->getUser()); | |
$this->notificationManager->send([$notification]); | |
} | |
} |
Thx, I'll go for an array though. Should have created two methods though, sendOne
and sendMany
;)
I think you should just choose send One) One notification is sent more often. And a few can be done through foreach)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix: