1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2017 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic, Inc. |
||
6 | * |
||
7 | * @link https://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\EmailBundle\Tests\Helper\Transport; |
||
13 | |||
14 | use Mautic\EmailBundle\Swiftmailer\Message\MauticMessage; |
||
15 | use Mautic\EmailBundle\Swiftmailer\Transport\InterfaceTokenTransport; |
||
16 | use Swift_Events_EventListener; |
||
17 | |||
18 | class BcInterfaceTokenTransport implements InterfaceTokenTransport, \Swift_Transport |
||
19 | { |
||
20 | private $fromAddresses = []; |
||
21 | private $metadatas = []; |
||
22 | private $validate = false; |
||
23 | private $maxRecipients; |
||
24 | private $numberToFail; |
||
25 | private $message; |
||
26 | |||
27 | /** |
||
28 | * BatchTransport constructor. |
||
29 | * |
||
30 | * @param bool $validate |
||
31 | */ |
||
32 | public function __construct($validate = false, $maxRecipients = 4, $numberToFail = 1) |
||
33 | { |
||
34 | $this->validate = $validate; |
||
35 | $this->maxRecipients = $maxRecipients; |
||
36 | $this->numberToFail = (int) $numberToFail; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param null $failedRecipients |
||
41 | */ |
||
42 | public function send(\Swift_Mime_SimpleMessage $message, &$failedRecipients = null) |
||
43 | { |
||
44 | $this->message = $message; |
||
45 | $this->fromAddresses[] = key($message->getFrom()); |
||
46 | $this->metadatas[] = $this->getMetadata(); |
||
47 | |||
48 | return true; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return int |
||
53 | */ |
||
54 | public function getMaxBatchLimit() |
||
55 | { |
||
56 | return $this->maxRecipients; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param int $toBeAdded |
||
61 | * @param string $type |
||
62 | * |
||
63 | * @return int |
||
64 | */ |
||
65 | public function getBatchRecipientCount(\Swift_Message $message, $toBeAdded = 1, $type = 'to') |
||
66 | { |
||
67 | $to = $message->getTo(); |
||
68 | $toCount = (is_array($to) || $to instanceof \Countable) ? count($to) : 0; |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
69 | |||
70 | return ('to' === $type) ? $toCount + $toBeAdded : $toCount; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return array |
||
75 | */ |
||
76 | public function getFromAddresses() |
||
77 | { |
||
78 | return $this->fromAddresses; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return array |
||
83 | */ |
||
84 | public function getMetadatas() |
||
85 | { |
||
86 | return $this->metadatas; |
||
87 | } |
||
88 | |||
89 | public function getMetadata() |
||
90 | { |
||
91 | return ($this->message instanceof MauticMessage) ? $this->message->getMetadata() : []; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return bool |
||
96 | */ |
||
97 | public function isStarted() |
||
98 | { |
||
99 | return true; |
||
100 | } |
||
101 | |||
102 | public function stop() |
||
103 | { |
||
104 | // ignore |
||
105 | } |
||
106 | |||
107 | public function registerPlugin(Swift_Events_EventListener $plugin) |
||
108 | { |
||
109 | // ignore |
||
110 | } |
||
111 | |||
112 | public function start() |
||
113 | { |
||
114 | // ignore |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @return bool |
||
119 | */ |
||
120 | public function ping() |
||
121 | { |
||
122 | return true; |
||
123 | } |
||
124 | } |
||
125 |