[ Index ]

MailPress 7.2

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

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/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      // needed as __construct is called from elsewhere explicitly
  26      public function __construct()
  27      {
  28          parent::__construct();
  29      }
  30  
  31      /**
  32       * {@inheritdoc}
  33       */
  34      public function ping()
  35      {
  36          $maxTransports = count($this->transports);
  37          for ($i = 0; $i < $maxTransports
  38              && $transport = $this->getNextTransport(); ++$i) {
  39              if ($transport->ping()) {
  40                  return true;
  41              } else {
  42                  $this->killCurrentTransport();
  43              }
  44          }
  45  
  46          return count($this->transports) > 0;
  47      }
  48  
  49      /**
  50       * Send the given Message.
  51       *
  52       * Recipient/sender data will be retrieved from the Message API.
  53       * The return value is the number of recipients who were accepted for delivery.
  54       *
  55       * @param string[] $failedRecipients An array of failures by-reference
  56       *
  57       * @return int
  58       */
  59      public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
  60      {
  61          $maxTransports = count($this->transports);
  62          $sent = 0;
  63          $this->lastUsedTransport = null;
  64  
  65          for ($i = 0; $i < $maxTransports
  66              && $transport = $this->getNextTransport(); ++$i) {
  67              try {
  68                  if (!$transport->isStarted()) {
  69                      $transport->start();
  70                  }
  71  
  72                  if ($sent = $transport->send($message, $failedRecipients)) {
  73                      $this->lastUsedTransport = $transport;
  74  
  75                      return $sent;
  76                  }
  77              } catch (Swift_TransportException $e) {
  78                  $this->killCurrentTransport();
  79              }
  80          }
  81  
  82          if (0 == count($this->transports)) {
  83              throw new Swift_TransportException('All Transports in FailoverTransport failed, or no Transports available');
  84          }
  85  
  86          return $sent;
  87      }
  88  
  89      protected function getNextTransport()
  90      {
  91          if (!isset($this->currentTransport)) {
  92              $this->currentTransport = parent::getNextTransport();
  93          }
  94  
  95          return $this->currentTransport;
  96      }
  97  
  98      protected function killCurrentTransport()
  99      {
 100          $this->currentTransport = null;
 101          parent::killCurrentTransport();
 102      }
 103  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1