src/EventSubscriber/MailerSubscriber.php line 35

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Kreno package.
  4.  *
  5.  * (c) Valentin Van Meeuwen <contact@wikub.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace App\EventSubscriber;
  11. use App\Service\EmailLog;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\Mailer\Event\MessageEvent;
  14. use Symfony\Component\Mime\Email;
  15. class MailerSubscriber implements EventSubscriberInterface
  16. {
  17.     private EmailLog $emailLog;
  18.     public function __construct(EmailLog $emailLog)
  19.     {
  20.         $this->emailLog $emailLog;
  21.     }
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [
  25.             MessageEvent::class => 'onMessage',
  26.         ];
  27.     }
  28.     public function onMessage(MessageEvent $event): void
  29.     {
  30.         $message $event->getMessage();
  31.         if (!$message instanceof Email) {
  32.             return;
  33.         }
  34.         $this->emailLog->log($message);
  35.     }
  36. }