summaryrefslogtreecommitdiff
path: root/vendor/swiftmailer/classes/Swift/Transport/FailoverTransport.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-08-15 17:23:41 -0700
committerFrédéric Guillot <fred@kanboard.net>2014-08-15 17:23:41 -0700
commit9eeded33f68872515954a2fc177fcb47a9273ae9 (patch)
treef3ef9507e087ca6bf3ce624232da240a8689b051 /vendor/swiftmailer/classes/Swift/Transport/FailoverTransport.php
parentc539bdc8ab746c5afd48cf87de057dc38d50adac (diff)
Add email notifications
Diffstat (limited to 'vendor/swiftmailer/classes/Swift/Transport/FailoverTransport.php')
-rw-r--r--vendor/swiftmailer/classes/Swift/Transport/FailoverTransport.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/vendor/swiftmailer/classes/Swift/Transport/FailoverTransport.php b/vendor/swiftmailer/classes/Swift/Transport/FailoverTransport.php
new file mode 100644
index 00000000..020bd057
--- /dev/null
+++ b/vendor/swiftmailer/classes/Swift/Transport/FailoverTransport.php
@@ -0,0 +1,86 @@
+<?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.
+ */
+
+/**
+ * Contains a list of redundant Transports so when one fails, the next is used.
+ *
+ * @author Chris Corbyn
+ */
+class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTransport
+{
+ /**
+ * Registered transport currently used.
+ *
+ * @var Swift_Transport
+ */
+ private $_currentTransport;
+
+ /**
+ * Creates a new FailoverTransport.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Send the given Message.
+ *
+ * Recipient/sender data will be retrieved 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 An array of 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 function _getNextTransport()
+ {
+ if (!isset($this->_currentTransport)) {
+ $this->_currentTransport = parent::_getNextTransport();
+ }
+
+ return $this->_currentTransport;
+ }
+
+ protected function _killCurrentTransport()
+ {
+ $this->_currentTransport = null;
+ parent::_killCurrentTransport();
+ }
+}