Files
ludikevent_crm/src/Service/Mailer/MailerSubscriber.php

36 lines
1.0 KiB
PHP
Raw Normal View History

<?php
namespace App\Service\Mailer;
use App\Service\Mailer\Event\CreatedAdminEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
#[AsEventListener(event: CreatedAdminEvent::class, method: 'onAdminEvent')]
class MailerSubscriber
{
public function __construct(
private readonly UrlGeneratorInterface $urlGenerator,
private readonly Mailer $mailer
) {
}
public function onAdminEvent(CreatedAdminEvent $createdAdminEvent): void
{
$account = $createdAdminEvent->getAccount();
$password = $createdAdminEvent->getPassword();
$this->mailer->send(
$account->getEmail(),
$account->getUsername(),
"[CRM] - Création d'un compte administrateur",
"mails/new_admin.twig",
[
'username' => $account->getUsername(),
'password' => $password,
'url' => $this->urlGenerator->generate('app_home'),
]
);
}
}