MessageLogger.php 1.4KB

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