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