This file contains 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 | |
namespace App\Message\Handler; | |
use Doctrine\ORM\EntityManagerInterface; | |
use Symfony\Component\Messenger\MessageBusInterface; | |
use App\Message\ConfirmCommandMailer; | |
use \Swift_Mailer; | |
/** | |
* Class ConfirmCommandMailerHandler | |
*/ | |
class ConfirmCommandMailerHandler | |
{ | |
/** | |
* @var Swift_Mailer | |
*/ | |
protected $mailer; | |
/** | |
* @var EntityManagerInterface | |
*/ | |
protected $entityManager; | |
/** | |
* ConfirmCommandMailerHandler constructor. | |
* @param \Swift_Mailer $mailer | |
* @param EntityManagerInterface $entityManager | |
*/ | |
public function __construct(Swift_Mailer $mailer, EntityManagerInterface $entityManager) | |
{ | |
$this->mailer = $mailer; | |
$this->entityManager = $entityManager; | |
} | |
/** | |
* @param ConfirmCommandMailer $message | |
*/ | |
public function __invoke(ConfirmCommandMailer $message) | |
{ | |
$command = $this->entityManager->getRepository(Command::class)->find($message->getCommandId()); | |
// verifier que les données sont cohérantes | |
$message = (new \Swift_Message('Commande confirmée')) | |
->setFrom('no-reply@example.com') | |
->setTo($command->getCustomer()->getEmail()) | |
->setBody( | |
"Commande #" . $command->getId() . " confirmée" | |
) | |
; | |
$this->mailer->send($message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment