Skip to content

Instantly share code, notes, and snippets.

@mikemix
Last active August 26, 2022 18:44
Show Gist options
  • Save mikemix/d7dc0a9c2c3bcdab6b7538d34c5c3c0e to your computer and use it in GitHub Desktop.
Save mikemix/d7dc0a9c2c3bcdab6b7538d34c5c3c0e to your computer and use it in GitHub Desktop.

Revisions

  1. mikemix revised this gist Aug 26, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion final-notification-subscriber.php
    Original file line number Diff line number Diff line change
    @@ -33,6 +33,6 @@ public function sendNotification(PostRegistrationEvent $event): void
    {
    $notification = ($this->notificationFactory($event->getUser());

    $this->notificationManager->send($notification);
    $this->notificationManager->send([$notification]);
    }
    }
  2. mikemix revised this gist Aug 21, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion final-notification-subscriber.php
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,8 @@
    use App\Notification\EmailNotificationInterface;
    use App\Notification\NotificationManagerInterface;
    use App\Events\PostRegistrationEvent;
    use App\Events\EventSubscriberInterface;
    use App\User\Notification\WelcomeGreetingEmailNotificationFactory;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;

    final class EmailNotification implements EventSubscriberInterface
    {
    @@ -23,6 +23,7 @@ public function __construct(
    $this->notificationFactory = $notificationFactory;
    }

    /** {@inheritDoc} */
    public static function getSubscribedEvents(): array
    {
    return [PostRegistrationEvent::NAME => 'sendNotification'];
  3. mikemix created this gist Aug 21, 2022.
    37 changes: 37 additions & 0 deletions final-notification-subscriber.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    <?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);
    }
    }