/framework/vendor/swift/lib/classes/Swift/Plugins/ReporterPlugin.php

http://zoop.googlecode.com/ · PHP · 82 lines · 42 code · 8 blank · 32 comment · 0 complexity · 2f1a90edb8eda47f02e8039bb35a7ed7 MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2004-2009 Chris Corbyn
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. //@require 'Swift/Events/SendListener.php';
  10. //@require 'Swift/Events/SendEvent.php';
  11. //@require 'Swift/Plugins/Reporter.php';
  12. /**
  13. * Does real time reporting of pass/fail for each recipient.
  14. * @package Swift
  15. * @subpackage Plugins
  16. * @author Chris Corbyn
  17. */
  18. class Swift_Plugins_ReporterPlugin
  19. implements Swift_Events_SendListener
  20. {
  21. /**
  22. * The reporter backend which takes notifications.
  23. * @var Swift_Plugin_Reporter
  24. * @access private
  25. */
  26. private $_reporter;
  27. /**
  28. * Create a new ReporterPlugin using $reporter.
  29. * @param Swift_Plugins_Reporter $reporter
  30. */
  31. public function __construct(Swift_Plugins_Reporter $reporter)
  32. {
  33. $this->_reporter = $reporter;
  34. }
  35. /**
  36. * Not used.
  37. */
  38. public function beforeSendPerformed(Swift_Events_SendEvent $evt)
  39. {
  40. }
  41. /**
  42. * Invoked immediately after the Message is sent.
  43. * @param Swift_Events_SendEvent $evt
  44. */
  45. public function sendPerformed(Swift_Events_SendEvent $evt)
  46. {
  47. $message = $evt->getMessage();
  48. $failures = array_flip($evt->getFailedRecipients());
  49. foreach ((array) $message->getTo() as $address => $null)
  50. {
  51. $this->_reporter->notify(
  52. $message, $address, (array_key_exists($address, $failures)
  53. ? Swift_Plugins_Reporter::RESULT_FAIL
  54. : Swift_Plugins_Reporter::RESULT_PASS)
  55. );
  56. }
  57. foreach ((array) $message->getCc() as $address => $null)
  58. {
  59. $this->_reporter->notify(
  60. $message, $address, (array_key_exists($address, $failures)
  61. ? Swift_Plugins_Reporter::RESULT_FAIL
  62. : Swift_Plugins_Reporter::RESULT_PASS)
  63. );
  64. }
  65. foreach ((array) $message->getBcc() as $address => $null)
  66. {
  67. $this->_reporter->notify(
  68. $message, $address, (array_key_exists($address, $failures)
  69. ? Swift_Plugins_Reporter::RESULT_FAIL
  70. : Swift_Plugins_Reporter::RESULT_PASS)
  71. );
  72. }
  73. }
  74. }