| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 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 |
|
|---|