diff options
author | Yuchen Pei <hi@ypei.me> | 2021-10-14 15:16:42 +1100 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2021-10-14 15:16:42 +1100 |
commit | 07f5140771388c9e0c8a99b0dd2e5d950bdb173b (patch) | |
tree | 323c00faef1edc7dea2e88ff581cc2258b2b6432 /External/swiftmailer/lib/classes/Swift/Transport/FailoverTransport.php | |
parent | e119be145500700f3c465e12664403a07530a421 (diff) |
moving h-source subdir out.
Diffstat (limited to 'External/swiftmailer/lib/classes/Swift/Transport/FailoverTransport.php')
-rwxr-xr-x | External/swiftmailer/lib/classes/Swift/Transport/FailoverTransport.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/External/swiftmailer/lib/classes/Swift/Transport/FailoverTransport.php b/External/swiftmailer/lib/classes/Swift/Transport/FailoverTransport.php new file mode 100755 index 0000000..e62491c --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Transport/FailoverTransport.php @@ -0,0 +1,97 @@ +<?php + +/* + * This file is part of SwiftMailer. + * (c) 2004-2009 Chris Corbyn + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +//@require 'Swift/Transport/LoadBalancedTransport.php'; +//@require 'Swift/Mime/Message.php'; + +/** + * Contains a list of redundant Transports so when one fails, the next is used. + * @package Swift + * @subpackage Transport + * @author Chris Corbyn + */ +class Swift_Transport_FailoverTransport + extends Swift_Transport_LoadBalancedTransport +{ + + /** + * Registered transport curently used. + * @var Swift_Transport + * @access private + */ + private $_currentTransport; + + /** + * Creates a new FailoverTransport. + */ + public function __construct() + { + parent::__construct(); + } + + /** + * Send the given Message. + * Recipient/sender data will be retreived from the Message API. + * The return value is the number of recipients who were accepted for delivery. + * @param Swift_Mime_Message $message + * @param string[] &$failedRecipients to collect failures by-reference + * @return int + */ + public function send(Swift_Mime_Message $message, &$failedRecipients = null) + { + $maxTransports = count($this->_transports); + $sent = 0; + + for ($i = 0; $i < $maxTransports + && $transport = $this->_getNextTransport(); ++$i) + { + try + { + if (!$transport->isStarted()) + { + $transport->start(); + } + + return $transport->send($message, $failedRecipients); + } + catch (Swift_TransportException $e) + { + $this->_killCurrentTransport(); + } + } + + if (count($this->_transports) == 0) + { + throw new Swift_TransportException( + 'All Transports in FailoverTransport failed, or no Transports available' + ); + } + + return $sent; + } + + // -- Protected methods + + protected function _getNextTransport() + { + if (!isset($this->_currentTransport)) + { + $this->_currentTransport = parent::_getNextTransport(); + } + return $this->_currentTransport; + } + + protected function _killCurrentTransport() + { + $this->_currentTransport = null; + parent::_killCurrentTransport(); + } + +} |