MessageLogger.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2011 Fabien Potencier
  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 all sent emails for further usage.
  11. *
  12. * @author Fabien Potencier
  13. */
  14. class Swift_Plugins_MessageLogger implements Swift_Events_SendListener
  15. {
  16. /**
  17. * @var Swift_Mime_SimpleMessage[]
  18. */
  19. private $messages;
  20. public function __construct()
  21. {
  22. $this->messages = [];
  23. }
  24. /**
  25. * Get the message list.
  26. *
  27. * @return Swift_Mime_SimpleMessage[]
  28. */
  29. public function getMessages()
  30. {
  31. return $this->messages;
  32. }
  33. /**
  34. * Get the message count.
  35. *
  36. * @return int count
  37. */
  38. public function countMessages()
  39. {
  40. return \count($this->messages);
  41. }
  42. /**
  43. * Empty the message list.
  44. */
  45. public function clear()
  46. {
  47. $this->messages = [];
  48. }
  49. /**
  50. * Invoked immediately before the Message is sent.
  51. */
  52. public function beforeSendPerformed(Swift_Events_SendEvent $evt)
  53. {
  54. $this->messages[] = clone $evt->getMessage();
  55. }
  56. /**
  57. * Invoked immediately after the Message is sent.
  58. */
  59. public function sendPerformed(Swift_Events_SendEvent $evt)
  60. {
  61. }
  62. }