fsi-open /
admin-security-bundle
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * (c) FSi sp. z o.o. <[email protected]> |
||
| 5 | * |
||
| 6 | * For the full copyright and license information, please view the LICENSE |
||
| 7 | * file that was distributed with this source code. |
||
| 8 | */ |
||
| 9 | |||
| 10 | declare(strict_types=1); |
||
| 11 | |||
| 12 | namespace FSi\Bundle\AdminSecurityBundle\Mailer; |
||
| 13 | |||
| 14 | use Swift_Mailer; |
||
| 15 | |||
| 16 | class TwigSwiftMailer implements MailerInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var Swift_Mailer |
||
| 20 | */ |
||
| 21 | private $mailer; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var SwiftMessageFactoryInterface |
||
| 25 | */ |
||
| 26 | private $messageFactory; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $templateName; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | private $fromEmail; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string|null |
||
| 40 | */ |
||
| 41 | private $replayToEmail; |
||
| 42 | |||
| 43 | public function __construct( |
||
| 44 | Swift_Mailer $mailer, |
||
| 45 | SwiftMessageFactoryInterface $messageFactory, |
||
| 46 | string $templateName, |
||
| 47 | string $fromEmail, |
||
| 48 | ?string $replayToEmail = null |
||
| 49 | ) { |
||
| 50 | $this->mailer = $mailer; |
||
| 51 | $this->messageFactory = $messageFactory; |
||
| 52 | $this->templateName = $templateName; |
||
| 53 | $this->fromEmail = $fromEmail; |
||
| 54 | $this->replayToEmail = $replayToEmail; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function send(EmailableInterface $to): int |
||
| 58 | { |
||
| 59 | $message = $this->messageFactory->createMessage($to->getEmail(), $this->templateName, ['receiver' => $to]); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 60 | $message->setFrom($this->fromEmail); |
||
| 61 | if (null !== $this->replayToEmail) { |
||
| 62 | $message->setReplyTo($this->replayToEmail); |
||
| 63 | } |
||
| 64 | |||
| 65 | return $this->mailer->send($message); |
||
| 66 | } |
||
| 67 | } |
||
| 68 |