MemorySpool.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2011 Fabien Potencier <fabien.potencier@gmail.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * Stores Messages in memory.
  11. * @package Swift
  12. * @author Fabien Potencier
  13. */
  14. class Swift_MemorySpool implements Swift_Spool
  15. {
  16. protected $messages = array();
  17. /**
  18. * Tests if this Transport mechanism has started.
  19. * @return boolean
  20. */
  21. public function isStarted()
  22. {
  23. return true;
  24. }
  25. /**
  26. * Starts this Transport mechanism.
  27. */
  28. public function start()
  29. {
  30. }
  31. /**
  32. * Stops this Transport mechanism.
  33. */
  34. public function stop()
  35. {
  36. }
  37. /**
  38. * Stores a message in the queue.
  39. *
  40. * @param Swift_Mime_Message $message The message to store
  41. */
  42. public function queueMessage(Swift_Mime_Message $message)
  43. {
  44. $this->messages[] = $message;
  45. }
  46. /**
  47. * Sends messages using the given transport instance.
  48. *
  49. * @param Swift_Transport $transport A transport instance
  50. * @param string[] &$failedRecipients An array of failures by-reference
  51. *
  52. * @return int The number of sent emails
  53. */
  54. public function flushQueue(Swift_Transport $transport, &$failedRecipients = null)
  55. {
  56. if (!$transport->isStarted())
  57. {
  58. $transport->start();
  59. }
  60. $count = 0;
  61. while ($message = array_pop($this->messages))
  62. {
  63. $count += $transport->send($message, $failedRecipients);
  64. }
  65. return $count;
  66. }
  67. }