|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of SwiftMailer. |
|
5
|
|
|
* (c) 2011 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 memory. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Fabien Potencier |
|
15
|
|
|
*/ |
|
16
|
|
|
class Swift_MemorySpool implements Swift_Spool |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
protected $messages = array(); |
|
19
|
|
|
|
|
20
|
2 |
|
public function __construct() |
|
21
|
|
|
{ |
|
22
|
2 |
|
Swift::$useMemorySpool = true; |
|
23
|
2 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Tests if this Transport mechanism has started. |
|
28
|
|
|
* |
|
29
|
|
|
* @return bool |
|
30
|
|
|
*/ |
|
31
|
|
|
public function isStarted() |
|
32
|
|
|
{ |
|
33
|
|
|
return true; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Starts this Transport mechanism. |
|
38
|
|
|
*/ |
|
39
|
|
|
public function start() |
|
40
|
|
|
{ |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Stops this Transport mechanism. |
|
45
|
|
|
*/ |
|
46
|
|
|
public function stop() |
|
47
|
|
|
{ |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Stores a message in the queue. |
|
52
|
|
|
* |
|
53
|
|
|
* @param Swift_Mime_Message $message The message to store |
|
54
|
|
|
* |
|
55
|
|
|
* @return bool Whether the operation has succeeded |
|
56
|
|
|
*/ |
|
57
|
2 |
|
public function queueMessage(Swift_Mime_Message $message) |
|
58
|
|
|
{ |
|
59
|
|
|
// clone the message to make sure it is not changed while in the queue |
|
60
|
2 |
|
$this->messages[] = clone $message; |
|
61
|
|
|
|
|
62
|
2 |
|
return true; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Sends messages using the given transport instance. |
|
67
|
|
|
* |
|
68
|
|
|
* @param Swift_Transport $transport A transport instance |
|
69
|
|
|
* @param string[] $failedRecipients An array of failures by-reference |
|
70
|
|
|
* |
|
71
|
|
|
* @return int The number of sent emails |
|
72
|
|
|
*/ |
|
73
|
2 |
|
public function flushQueue(Swift_Transport $transport, &$failedRecipients = null) |
|
74
|
|
|
{ |
|
75
|
2 |
|
if (!$this->messages) { |
|
|
|
|
|
|
76
|
|
|
return 0; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
2 |
|
if (!$transport->isStarted()) { |
|
80
|
|
|
$transport->start(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
2 |
|
$count = 0; |
|
84
|
2 |
|
while ($message = array_pop($this->messages)) { |
|
85
|
2 |
|
$count += $transport->send($message, $failedRecipients); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
2 |
|
return $count; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
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.