|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\Mail\Transport; |
|
4
|
|
|
|
|
5
|
|
|
use Swift_Events_EventListener; |
|
6
|
|
|
use Swift_Events_SendEvent; |
|
7
|
|
|
use Swift_Mime_SimpleMessage; |
|
8
|
|
|
use Swift_Transport as SwiftTransport; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class AbstractTransport |
|
12
|
|
|
* @package Nip\Mail\Transport |
|
13
|
|
|
*/ |
|
14
|
|
|
abstract class AbstractTransport implements SwiftTransport |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* The plug-ins registered with the transport. |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
public $plugins = []; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
public function isStarted() |
|
27
|
|
|
{ |
|
28
|
|
|
return true; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritdoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
public function start() |
|
35
|
|
|
{ |
|
36
|
|
|
return true; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
|
|
public function stop() |
|
43
|
|
|
{ |
|
44
|
|
|
return true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
public function ping() |
|
51
|
|
|
{ |
|
52
|
|
|
return true; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Register a plug-in with the transport. |
|
57
|
|
|
* |
|
58
|
|
|
* @param Swift_Events_EventListener $plugin |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
|
|
public function registerPlugin(Swift_Events_EventListener $plugin) |
|
62
|
|
|
{ |
|
63
|
|
|
array_push($this->plugins, $plugin); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Iterate through registered plugins and execute plugins' methods. |
|
68
|
|
|
* |
|
69
|
|
|
* @param \Swift_Mime_SimpleMessage $message |
|
70
|
|
|
* @return void |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function beforeSendPerformed(Swift_Mime_SimpleMessage $message) |
|
73
|
|
|
{ |
|
74
|
|
|
$event = new Swift_Events_SendEvent($this, $message); |
|
75
|
|
|
|
|
76
|
|
|
foreach ($this->plugins as $plugin) { |
|
77
|
|
|
if (method_exists($plugin, 'beforeSendPerformed')) { |
|
78
|
|
|
$plugin->beforeSendPerformed($event); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Iterate through registered plugins and execute plugins' methods. |
|
85
|
|
|
* |
|
86
|
|
|
* @param \Swift_Mime_SimpleMessage $message |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function sendPerformed(Swift_Mime_SimpleMessage $message) |
|
90
|
|
|
{ |
|
91
|
|
|
$event = new Swift_Events_SendEvent($this, $message); |
|
92
|
|
|
|
|
93
|
|
|
foreach ($this->plugins as $plugin) { |
|
94
|
|
|
if (method_exists($plugin, 'sendPerformed')) { |
|
95
|
|
|
$plugin->sendPerformed($event); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get the number of recipients. |
|
102
|
|
|
* |
|
103
|
|
|
* @param \Swift_Mime_SimpleMessage $message |
|
104
|
|
|
* @return int |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function numberOfRecipients(Swift_Mime_SimpleMessage $message) |
|
107
|
|
|
{ |
|
108
|
|
|
return count(array_merge( |
|
109
|
|
|
(array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc() |
|
110
|
|
|
)); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|