MessageLogger.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 array
  18. */
  19. private $messages;
  20. public function __construct()
  21. {
  22. $this->messages = array();
  23. }
  24. /**
  25. * Get the message list
  26. *
  27. * @return array
  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. */
  46. public function clear()
  47. {
  48. $this->messages = array();
  49. }
  50. /**
  51. * Invoked immediately before the Message is sent.
  52. *
  53. * @param Swift_Events_SendEvent $evt
  54. */
  55. public function beforeSendPerformed(Swift_Events_SendEvent $evt)
  56. {
  57. $this->messages[] = clone $evt->getMessage();
  58. }
  59. /**
  60. * Invoked immediately after the Message is sent.
  61. *
  62. * @param Swift_Events_SendEvent $evt
  63. */
  64. public function sendPerformed(Swift_Events_SendEvent $evt)
  65. {
  66. }
  67. }