Development

/branches/1.4/lib/mailer/sfMailerMessageLoggerPlugin.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/mailer/sfMailerMessageLoggerPlugin.class.php

Revision 23810, 1.9 kB (checked in by Kris.Wallsmith, 5 years ago)

[1.3] set svn:eol-style property to native and svn:keywords property to Id on all .php files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
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 /**
12  * sfMailerMessageLoggerPlugin is a Swift plugin to log all sent messages.
13  *
14  * @package    symfony
15  * @subpackage mailer
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfMailerMessageLoggerPlugin implements Swift_Events_SendListener
20 {
21   protected
22     $messages   = array(),
23     $dispatcher = null;
24
25   /**
26    * Constructor.
27    *
28    * @param sfEventDispatcher $dispatcher An event dispatcher instance
29    */
30   public function __construct(sfEventDispatcher $dispatcher)
31   {
32     $this->dispatcher = $dispatcher;
33   }
34
35   /**
36    * Clears all the messages.
37    */
38   public function clear()
39   {
40     $this->messages = array();
41   }
42
43   /**
44    * Gets all logged messages.
45    *
46    * @return array An array of message instances
47    */
48   public function getMessages()
49   {
50     return $this->messages;
51   }
52
53   /**
54    * Returns the number of logged messages.
55    *
56    * @return int The number if logged messages
57    */
58   public function countMessages()
59   {
60     return count($this->messages);
61   }
62
63   /**
64    * Invoked immediately before the Message is sent.
65    *
66    * @param Swift_Events_SendEvent $evt
67    */
68   public function beforeSendPerformed(Swift_Events_SendEvent $evt)
69   {
70     $this->messages[] = $message = clone $evt->getMessage();
71
72     $to = null === $message->getTo() ? '' : implode(', ', array_keys($message->getTo()));
73
74     $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Sending email "%s" to "%s"', $message->getSubject(), $to))));
75   }
76
77   /**
78    * Invoked immediately after the Message is sent.
79    *
80    * @param Swift_Events_SendEvent $evt
81    */
82   public function sendPerformed(Swift_Events_SendEvent $evt)
83   {
84   }
85 }
86
Note: See TracBrowser for help on using the browser.