vendor/swiftmailer/lib/classes/Swift/Transport/SpoolTransport.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of SwiftMailer.
       
     5  * (c) 2009 Fabien Potencier <fabien.potencier@gmail.com>
       
     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  * Stores Messages in a queue.
       
    13  * @package Swift
       
    14  * @author  Fabien Potencier
       
    15  */
       
    16 class Swift_Transport_SpoolTransport implements Swift_Transport
       
    17 {
       
    18   /** The spool instance */
       
    19   private $_spool;
       
    20 
       
    21   /** The event dispatcher from the plugin API */
       
    22   private $_eventDispatcher;
       
    23 
       
    24   /**
       
    25    * Constructor.
       
    26    */
       
    27   public function __construct(Swift_Events_EventDispatcher $eventDispatcher, Swift_Spool $spool = null)
       
    28   {
       
    29     $this->_eventDispatcher = $eventDispatcher;
       
    30     $this->_spool = $spool;
       
    31   }
       
    32   
       
    33   /**
       
    34    * Sets the spool object.
       
    35    * @param Swift_Spool $spool
       
    36    */
       
    37   public function setSpool(Swift_Spool $spool)
       
    38   {
       
    39     $this->_spool = $spool;
       
    40     return $this;
       
    41   }
       
    42   
       
    43   /**
       
    44    * Get the spool object.
       
    45    * @return Swift_Spool
       
    46    */
       
    47   public function getSpool()
       
    48   {
       
    49     return $this->_spool;
       
    50   }
       
    51   
       
    52   /**
       
    53    * Tests if this Transport mechanism has started.
       
    54    *
       
    55    * @return boolean
       
    56    */
       
    57   public function isStarted()
       
    58   {
       
    59     return true;
       
    60   }
       
    61   
       
    62   /**
       
    63    * Starts this Transport mechanism.
       
    64    */
       
    65   public function start()
       
    66   {
       
    67   }
       
    68   
       
    69   /**
       
    70    * Stops this Transport mechanism.
       
    71    */
       
    72   public function stop()
       
    73   {
       
    74   }
       
    75   
       
    76   /**
       
    77    * Sends the given message.
       
    78    *
       
    79    * @param Swift_Mime_Message $message
       
    80    * @param string[] &$failedRecipients to collect failures by-reference
       
    81    *
       
    82    * @return int The number of sent emails
       
    83    */
       
    84   public function send(Swift_Mime_Message $message, &$failedRecipients = null)
       
    85   {
       
    86     if ($evt = $this->_eventDispatcher->createSendEvent($this, $message))
       
    87     {
       
    88       $this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
       
    89       if ($evt->bubbleCancelled())
       
    90       {
       
    91         return 0;
       
    92       }
       
    93     }
       
    94     
       
    95     $success = $this->_spool->queueMessage($message);
       
    96     
       
    97     if ($evt)
       
    98     {
       
    99       $evt->setResult($success ? Swift_Events_SendEvent::RESULT_SUCCESS : Swift_Events_SendEvent::RESULT_FAILED);
       
   100       $this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
       
   101     }
       
   102     
       
   103     return 1;
       
   104   }
       
   105   
       
   106   /**
       
   107    * Register a plugin.
       
   108    *
       
   109    * @param Swift_Events_EventListener $plugin
       
   110    */
       
   111   public function registerPlugin(Swift_Events_EventListener $plugin)
       
   112   {
       
   113     $this->_eventDispatcher->bindEventListener($plugin);
       
   114   }
       
   115 }