src/InvoiceBundle/Listener/Mailer/InvoiceMailerListener.php line 39

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of SolidInvoice project.
  5.  *
  6.  * (c) Pierre du Plessis <open-source@solidworx.co>
  7.  *
  8.  * This source file is subject to the MIT license that is bundled
  9.  * with this source code in the file LICENSE.
  10.  */
  11. namespace SolidInvoice\InvoiceBundle\Listener\Mailer;
  12. use SolidInvoice\InvoiceBundle\Email\InvoiceEmail;
  13. use SolidInvoice\InvoiceBundle\Event\InvoiceEvent;
  14. use SolidInvoice\InvoiceBundle\Event\InvoiceEvents;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\Mailer\MailerInterface;
  17. /**
  18.  * @see \SolidInvoice\InvoiceBundle\Tests\Listener\Mailer\InvoiceMailerListenerTest
  19.  */
  20. class InvoiceMailerListener implements EventSubscriberInterface
  21. {
  22.     public function __construct(
  23.         private readonly MailerInterface $mailer
  24.     ) {
  25.     }
  26.     public static function getSubscribedEvents(): array
  27.     {
  28.         return [
  29.             InvoiceEvents::INVOICE_POST_ACCEPT => 'onInvoiceAccepted',
  30.         ];
  31.     }
  32.     public function onInvoiceAccepted(InvoiceEvent $event): void
  33.     {
  34.         $this->mailer->send(new InvoiceEmail($event->getInvoice()));
  35.     }
  36. }