TYPO3  7.6
Transport/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 
17 {
24 
28  public function __construct()
29  {
30  parent::__construct();
31  }
32 
44  public function send(Swift_Mime_Message $message, &$failedRecipients = null)
45  {
46  $maxTransports = count($this->_transports);
47  $sent = 0;
48 
49  for ($i = 0; $i < $maxTransports
50  && $transport = $this->_getNextTransport(); ++$i) {
51  try {
52  if (!$transport->isStarted()) {
53  $transport->start();
54  }
55 
56  return $transport->send($message, $failedRecipients);
57  } catch (Swift_TransportException $e) {
58  $this->_killCurrentTransport();
59  }
60  }
61 
62  if (count($this->_transports) == 0) {
63  throw new Swift_TransportException(
64  'All Transports in FailoverTransport failed, or no Transports available'
65  );
66  }
67 
68  return $sent;
69  }
70 
71  protected function _getNextTransport()
72  {
73  if (!isset($this->_currentTransport)) {
74  $this->_currentTransport = parent::_getNextTransport();
75  }
76 
78  }
79 
80  protected function _killCurrentTransport()
81  {
82  $this->_currentTransport = null;
83  parent::_killCurrentTransport();
84  }
85 }