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
|
|
|
/** |
26
|
|
|
* Creates a new FailoverTransport. |
27
|
|
|
*/ |
28
|
|
|
public function __construct() |
29
|
|
|
{ |
30
|
|
|
parent::__construct(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Send the given Message. |
35
|
|
|
* |
36
|
|
|
* Recipient/sender data will be retrieved from the Message API. |
37
|
8 |
|
* The return value is the number of recipients who were accepted for delivery. |
38
|
|
|
* |
39
|
8 |
|
* @param Swift_Mime_Message $message |
40
|
8 |
|
* @param string[] $failedRecipients An array of failures by-reference |
41
|
8 |
|
* |
42
|
|
|
* @return int |
43
|
8 |
|
* @throws Swift_TransportException |
44
|
8 |
|
*/ |
45
|
|
View Code Duplication |
public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
|
|
|
|
46
|
8 |
|
{ |
47
|
8 |
|
$maxTransports = count($this->_transports); |
48
|
8 |
|
$sent = 0; |
49
|
|
|
$this->_lastUsedTransport = null; |
50
|
8 |
|
|
51
|
6 |
|
for ($i = 0; $i < $maxTransports |
52
|
4 |
|
&& $transport = $this->_getNextTransport(); ++$i) { |
53
|
|
|
try { |
54
|
4 |
|
if (!$transport->isStarted()) { |
55
|
|
|
$transport->start(); |
56
|
|
|
} |
57
|
7 |
|
|
58
|
5 |
|
$sent = $transport->send($message, $failedRecipients); |
59
|
|
|
if ($sent) { |
60
|
7 |
|
$this->_lastUsedTransport = $transport; |
61
|
|
|
|
62
|
5 |
|
return $sent; |
63
|
3 |
|
} |
64
|
|
|
|
65
|
3 |
|
} catch (Swift_TransportException $e) { |
66
|
|
|
$this->_killCurrentTransport(); |
67
|
|
|
} |
68
|
2 |
|
} |
69
|
|
|
|
70
|
|
|
if (count($this->_transports) === 0) { |
71
|
8 |
|
throw new Swift_TransportException( |
72
|
|
|
'All Transports in FailoverTransport failed, or no Transports available' |
73
|
8 |
|
); |
74
|
8 |
|
} |
75
|
8 |
|
|
76
|
|
|
return $sent; |
77
|
8 |
|
} |
78
|
|
|
|
79
|
|
|
protected function _getNextTransport() |
80
|
5 |
|
{ |
81
|
|
|
if (!isset($this->_currentTransport)) { |
82
|
5 |
|
$this->_currentTransport = parent::_getNextTransport(); |
83
|
5 |
|
} |
84
|
5 |
|
|
85
|
|
|
return $this->_currentTransport; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function _killCurrentTransport() |
89
|
|
|
{ |
90
|
|
|
$this->_currentTransport = null; |
91
|
|
|
parent::_killCurrentTransport(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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.