XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
FailoverTransport.php
Go to the documentation of this file.
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 //@require 'Swift/Transport/LoadBalancedTransport.php';
12 //@require 'Swift/Mime/Message.php';
13 
22 {
23 
30 
34  public function __construct()
35  {
37  }
38 
47  public function send(Swift_Mime_Message $message, &$failedRecipients = null)
48  {
49  $maxTransports = count($this->_transports);
50  $sent = 0;
51 
52  for ($i = 0; $i < $maxTransports
53  && $transport = $this->_getNextTransport(); ++$i)
54  {
55  try
56  {
57  if (!$transport->isStarted())
58  {
59  $transport->start();
60  }
61 
62  return $transport->send($message, $failedRecipients);
63  }
64  catch (Swift_TransportException $e)
65  {
66  $this->_killCurrentTransport();
67  }
68  }
69 
70  if (count($this->_transports) == 0)
71  {
72  throw new Swift_TransportException(
73  'All Transports in FailoverTransport failed, or no Transports available'
74  );
75  }
76 
77  return $sent;
78  }
79 
80  // -- Protected methods
81 
82  protected function _getNextTransport()
83  {
84  if (!isset($this->_currentTransport))
85  {
86  $this->_currentTransport = parent::_getNextTransport();
87  }
89  }
90 
91  protected function _killCurrentTransport()
92  {
93  $this->_currentTransport = null;
94  parent::_killCurrentTransport();
95  }
96 
97 }