MessageLogger.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * @package Swift
  12. * @subpackage Plugins
  13. * @author Fabien Potencier
  14. */
  15. class Swift_Plugins_MessageLogger
  16. implements Swift_Events_SendListener
  17. {
  18. /**
  19. * @var array
  20. */
  21. private $messages;
  22. public function __construct()
  23. {
  24. $this->messages = array();
  25. }
  26. /**
  27. * Get the message list
  28. *
  29. * @return array
  30. */
  31. public function getMessages()
  32. {
  33. return $this->messages;
  34. }
  35. /**
  36. * Get the message count
  37. *
  38. * @return int count
  39. */
  40. public function countMessages()
  41. {
  42. return count($this->messages);
  43. }
  44. /**
  45. * Empty the message list
  46. *
  47. */
  48. public function clear()
  49. {
  50. $this->messages = array();
  51. }
  52. /**
  53. * Invoked immediately before the Message is sent.
  54. *
  55. * @param Swift_Events_SendEvent $evt
  56. */
  57. public function beforeSendPerformed(Swift_Events_SendEvent $evt)
  58. {
  59. $this->messages[] = clone $evt->getMessage();
  60. }
  61. /**
  62. * Invoked immediately after the Message is sent.
  63. *
  64. * @param Swift_Events_SendEvent $evt
  65. */
  66. public function sendPerformed(Swift_Events_SendEvent $evt)
  67. {
  68. }
  69. }