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