Completed
Push — master ( d67956...a656c9 )
by Piotr
11s
created

TwigSwiftMailer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 5
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
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
namespace FSi\Bundle\AdminSecurityBundle\Mailer;
11
12
use Swift_Mailer;
13
14
class TwigSwiftMailer implements MailerInterface
15
{
16
    /**
17
     * @var Swift_Mailer
18
     */
19
    private $mailer;
20
21
    /**
22
     * @var SwiftMessageFactoryInterface
23
     */
24
    private $messageFactory;
25
26
    /**
27
     * @var string
28
     */
29
    private $templateName;
30
31
    /**
32
     * @var string
33
     */
34
    private $fromEmail;
35
36
    /**
37
     * @var string|null
38
     */
39
    private $replayToEmail;
40
41
    /**
42
     * @param Swift_Mailer $mailer
43
     * @param SwiftMessageFactoryInterface $messageFactory
44
     * @param string $templateName
45
     * @param string $fromEmail
46
     * @param string $replayToEmail
47
     */
48
    public function __construct(
49
        Swift_Mailer $mailer,
50
        SwiftMessageFactoryInterface $messageFactory,
51
        $templateName,
52
        $fromEmail,
53
        $replayToEmail = null
54
    ) {
55
        $this->mailer = $mailer;
56
        $this->messageFactory = $messageFactory;
57
        $this->templateName = $templateName;
58
        $this->fromEmail = $fromEmail;
59
        $this->replayToEmail = $replayToEmail;
60
    }
61
62
    /**
63
     * @param EmailableInterface $to
64
     * @return int
65
     */
66
    public function send(EmailableInterface $to)
67
    {
68
        $message = $this->messageFactory->createMessage($to->getEmail(), $this->templateName, ['receiver' => $to]);
69
        $message->setFrom($this->fromEmail);
70
        if (isset($this->replayToEmail)) {
71
            $message->setReplyTo($this->replayToEmail);
72
        }
73
74
        return $this->mailer->send($message);
75
    }
76
}
77