1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of SwiftMailer. |
5
|
|
|
* (c) 2009 Fabien Potencier <[email protected]> |
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
|
|
|
* |
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
|
1 |
|
public function __construct(Swift_Events_EventDispatcher $eventDispatcher, Swift_Spool $spool = null) |
28
|
|
|
{ |
29
|
1 |
|
$this->_eventDispatcher = $eventDispatcher; |
30
|
1 |
|
$this->_spool = $spool; |
31
|
1 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Sets the spool object. |
35
|
|
|
* |
36
|
|
|
* @param Swift_Spool $spool |
37
|
|
|
* |
38
|
|
|
* @return Swift_Transport_SpoolTransport |
39
|
|
|
*/ |
40
|
|
|
public function setSpool(Swift_Spool $spool) |
41
|
|
|
{ |
42
|
|
|
$this->_spool = $spool; |
43
|
|
|
|
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get the spool object. |
49
|
|
|
* |
50
|
|
|
* @return Swift_Spool |
51
|
|
|
*/ |
52
|
|
|
public function getSpool() |
53
|
|
|
{ |
54
|
|
|
return $this->_spool; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Tests if this Transport mechanism has started. |
59
|
|
|
* |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
|
|
public function isStarted() |
63
|
|
|
{ |
64
|
|
|
return true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Starts this Transport mechanism. |
69
|
|
|
*/ |
70
|
|
|
public function start() |
71
|
|
|
{ |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Stops this Transport mechanism. |
76
|
|
|
*/ |
77
|
|
|
public function stop() |
78
|
|
|
{ |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Check if this Transport mechanism is alive. |
83
|
|
|
* |
84
|
|
|
* If a Transport mechanism session is no longer functional, the method |
85
|
|
|
* returns FALSE. It is the responsibility of the developer to handle this |
86
|
|
|
* case and restart the Transport mechanism manually. |
87
|
|
|
* |
88
|
|
|
* @example |
89
|
|
|
* |
90
|
|
|
* if (!$transport->ping()) { |
91
|
|
|
* $transport->stop(); |
92
|
|
|
* $transport->start(); |
93
|
|
|
* } |
94
|
|
|
* |
95
|
|
|
* The Transport mechanism will be started, if it is not already. |
96
|
|
|
* |
97
|
|
|
* It is undefined if the Transport mechanism attempts to restart as long as |
98
|
|
|
* the return value reflects whether the mechanism is now functional. |
99
|
|
|
* |
100
|
|
|
* @return bool TRUE if the transport is alive |
101
|
|
|
*/ |
102
|
|
|
public function ping() |
103
|
|
|
{ |
104
|
|
|
return true; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Sends the given message. |
109
|
|
|
* |
110
|
|
|
* @param Swift_Mime_Message $message |
111
|
|
|
* @param string[] $failedRecipients An array of failures by-reference |
112
|
|
|
* |
113
|
|
|
* @return int The number of sent e-mail's |
114
|
|
|
*/ |
115
|
|
|
public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
116
|
|
|
{ |
117
|
|
|
$evt = $this->_eventDispatcher->createSendEvent($this, $message); |
118
|
|
|
if ($evt) { |
119
|
|
|
|
120
|
|
|
$this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed'); |
121
|
|
|
if ($evt->bubbleCancelled()) { |
122
|
|
|
return 0; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$success = $this->_spool->queueMessage($message); |
127
|
|
|
|
128
|
|
|
if ($evt) { |
129
|
|
|
$evt->setResult($success ? Swift_Events_SendEvent::RESULT_SPOOLED : Swift_Events_SendEvent::RESULT_FAILED); |
130
|
|
|
$this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return 1; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Register a plugin. |
138
|
|
|
* |
139
|
|
|
* @param Swift_Events_EventListener $plugin |
140
|
|
|
*/ |
141
|
|
|
public function registerPlugin(Swift_Events_EventListener $plugin) |
142
|
|
|
{ |
143
|
|
|
$this->_eventDispatcher->bindEventListener($plugin); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.