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: * @return Swift_Transport_SpoolTransport
37: */
38: public function setSpool(Swift_Spool $spool)
39: {
40: $this->_spool = $spool;
41:
42: return $this;
43: }
44:
45: /**
46: * Get the spool object.
47: * @return Swift_Spool
48: */
49: public function getSpool()
50: {
51: return $this->_spool;
52: }
53:
54: /**
55: * Tests if this Transport mechanism has started.
56: *
57: * @return boolean
58: */
59: public function isStarted()
60: {
61: return true;
62: }
63:
64: /**
65: * Starts this Transport mechanism.
66: */
67: public function start()
68: {
69: }
70:
71: /**
72: * Stops this Transport mechanism.
73: */
74: public function stop()
75: {
76: }
77:
78: /**
79: * Sends the given message.
80: *
81: * @param Swift_Mime_Message $message
82: * @param string[] &$failedRecipients to collect failures by-reference
83: *
84: * @return int The number of sent emails
85: */
86: public function send(Swift_Mime_Message $message, &$failedRecipients = null)
87: {
88: if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
89: $this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
90: if ($evt->bubbleCancelled()) {
91: return 0;
92: }
93: }
94:
95: $success = $this->_spool->queueMessage($message);
96:
97: if ($evt) {
98: $evt->setResult($success ? Swift_Events_SendEvent::RESULT_SUCCESS : Swift_Events_SendEvent::RESULT_FAILED);
99: $this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
100: }
101:
102: return 1;
103: }
104:
105: /**
106: * Register a plugin.
107: *
108: * @param Swift_Events_EventListener $plugin
109: */
110: public function registerPlugin(Swift_Events_EventListener $plugin)
111: {
112: $this->_eventDispatcher->bindEventListener($plugin);
113: }
114: }
115: