|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of SwiftMailer. |
|
5
|
|
|
* (c) 2004-2009 Chris Corbyn |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Contains a list of redundant Transports so when one fails, the next is used. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Chris Corbyn |
|
15
|
|
|
*/ |
|
16
|
|
|
class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTransport |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Registered transport currently used. |
|
20
|
|
|
* |
|
21
|
|
|
* @var Swift_Transport |
|
22
|
|
|
*/ |
|
23
|
|
|
private $_currentTransport; |
|
24
|
|
|
|
|
25
|
|
|
// needed as __construct is called from elsewhere explicitly |
|
26
|
11 |
|
public function __construct() |
|
27
|
|
|
{ |
|
28
|
11 |
|
parent::__construct(); |
|
29
|
11 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Send the given Message. |
|
33
|
|
|
* |
|
34
|
|
|
* Recipient/sender data will be retrieved from the Message API. |
|
35
|
|
|
* The return value is the number of recipients who were accepted for delivery. |
|
36
|
|
|
* |
|
37
|
|
|
* @param Swift_Mime_Message $message |
|
38
|
|
|
* @param string[] $failedRecipients An array of failures by-reference |
|
39
|
|
|
* |
|
40
|
|
|
* @return int |
|
41
|
|
|
* @throws Swift_TransportException |
|
42
|
|
|
*/ |
|
43
|
8 |
View Code Duplication |
public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
8 |
|
$maxTransports = count($this->_transports); |
|
46
|
8 |
|
$sent = 0; |
|
47
|
8 |
|
$this->_lastUsedTransport = null; |
|
48
|
|
|
|
|
49
|
8 |
|
for ($i = 0; $i < $maxTransports |
|
50
|
8 |
|
&& $transport = $this->_getNextTransport(); ++$i) { |
|
51
|
|
|
try { |
|
52
|
8 |
|
if (!$transport->isStarted()) { |
|
53
|
8 |
|
$transport->start(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
8 |
|
$sent = $transport->send($message, $failedRecipients); |
|
57
|
6 |
|
if ($sent) { |
|
58
|
4 |
|
$this->_lastUsedTransport = $transport; |
|
59
|
|
|
|
|
60
|
6 |
|
return $sent; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
5 |
|
} catch (Swift_TransportException $e) { |
|
64
|
5 |
|
$this->_killCurrentTransport(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
5 |
|
if (count($this->_transports) === 0) { |
|
69
|
3 |
|
throw new Swift_TransportException( |
|
70
|
3 |
|
'All Transports in FailoverTransport failed, or no Transports available' |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
2 |
|
return $sent; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
8 |
|
protected function _getNextTransport() |
|
78
|
|
|
{ |
|
79
|
8 |
|
if (!isset($this->_currentTransport)) { |
|
80
|
8 |
|
$this->_currentTransport = parent::_getNextTransport(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
8 |
|
return $this->_currentTransport; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
5 |
|
protected function _killCurrentTransport() |
|
87
|
|
|
{ |
|
88
|
5 |
|
$this->_currentTransport = null; |
|
89
|
5 |
|
parent::_killCurrentTransport(); |
|
90
|
5 |
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.