[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/Swiftmailer/classes/Swift/Transport/ -> FailoverTransport.php (source)

   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  /**
  12   * Contains a list of redundant Transports so when one fails, the next is used.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTransport
  17  {
  18      /**
  19       * Registered transport currently used.
  20       *
  21       * @var Swift_Transport
  22       */
  23      private $_currentTransport;
  24  
  25      /**
  26       * Creates a new FailoverTransport.
  27       */
  28      public function __construct()
  29      {
  30          parent::__construct();
  31      }
  32  
  33      /**
  34       * Send the given Message.
  35       *
  36       * Recipient/sender data will be retrieved from the Message API.
  37       * The return value is the number of recipients who were accepted for delivery.
  38       *
  39       * @param Swift_Mime_Message $message
  40       * @param string[]           $failedRecipients An array of failures by-reference
  41       *
  42       * @return int
  43       */
  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  
  77          return $this->_currentTransport;
  78      }
  79  
  80      protected function _killCurrentTransport()
  81      {
  82          $this->_currentTransport = null;
  83          parent::_killCurrentTransport();
  84      }
  85  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1