1: <?php
2:
3: /**
4: * Avisota newsletter and mailing system
5: *
6: * PHP Version 5.3
7: *
8: * @copyright bit3 UG 2013
9: * @author Tristan Lins <tristan.lins@bit3.de>
10: * @package avisota-core
11: * @license LGPL-3.0+
12: * @link http://avisota.org
13: */
14:
15: namespace Avisota\Transport;
16:
17: use Avisota\Message\MessageInterface;
18:
19: /**
20: * Abstract transport using a swift transport.
21: *
22: * @package avisota-core
23: */
24: abstract class AbstractSwiftTransport extends AbstractTransport
25: {
26: /**
27: * @var \Swift_Mailer|null
28: */
29: protected $swiftMailer;
30:
31: /**
32: * @return \Swift_Mailer
33: */
34: abstract protected function createMailer();
35:
36: /**
37: * @return void
38: */
39: protected function resetMailer()
40: {
41: $this->swiftMailer = null;
42: }
43:
44: /**
45: * {@inheritdoc}
46: */
47: public function initialise()
48: {
49: if (!$this->swiftMailer) {
50: $this->swiftMailer = $this->createMailer();
51: }
52: }
53:
54: /**
55: * {@inheritdoc}
56: */
57: public function flush()
58: {
59: }
60:
61: /**
62: * {@inheritdoc}
63: */
64: public function send(MessageInterface $message)
65: {
66: $email = $this->renderer->renderMessage($message);
67:
68: $failedRecipients = array();
69: $successfullySendCount = $this->swiftMailer->send($email, $failedRecipients);
70:
71: return new TransportStatus($message, $successfullySendCount, $failedRecipients);
72: }
73: }
74: