1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16:
17: class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTransport
18: {
19: 20: 21: 22: 23:
24: private $_currentTransport;
25:
26: 27: 28:
29: public function __construct()
30: {
31: parent::__construct();
32: }
33:
34: 35: 36: 37: 38: 39: 40: 41:
42: public function send(Swift_Mime_Message $message, &$failedRecipients = null)
43: {
44: $maxTransports = count($this->_transports);
45: $sent = 0;
46:
47: for ($i = 0; $i < $maxTransports
48: && $transport = $this->_getNextTransport(); ++$i)
49: {
50: try {
51: if (!$transport->isStarted()) {
52: $transport->start();
53: }
54:
55: return $transport->send($message, $failedRecipients);
56: } catch (Swift_TransportException $e) {
57: $this->_killCurrentTransport();
58: }
59: }
60:
61: if (count($this->_transports) == 0) {
62: throw new Swift_TransportException(
63: 'All Transports in FailoverTransport failed, or no Transports available'
64: );
65: }
66:
67: return $sent;
68: }
69:
70:
71:
72: protected function _getNextTransport()
73: {
74: if (!isset($this->_currentTransport)) {
75: $this->_currentTransport = parent::_getNextTransport();
76: }
77:
78: return $this->_currentTransport;
79: }
80:
81: protected function _killCurrentTransport()
82: {
83: $this->_currentTransport = null;
84: parent::_killCurrentTransport();
85: }
86: }
87: