Development

/branches/1.4/lib/debug/sfWebDebugPanelMailer.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/debug/sfWebDebugPanelMailer.class.php

Revision 23810, 2.7 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  * sfWebDebugPanelMailer adds a panel to the web debug toolbar with sent emails.
13  *
14  * @package    symfony
15  * @subpackage debug
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfWebDebugPanelMailer extends sfWebDebugPanel
20 {
21   protected $mailer = null;
22
23   /**
24    * Constructor.
25    *
26    * @param sfWebDebug $webDebug The web debug toolbar instance
27    */
28   public function __construct(sfWebDebug $webDebug)
29   {
30     parent::__construct($webDebug);
31
32     $this->webDebug->getEventDispatcher()->connect('mailer.configure', array($this, 'listenForMailerConfigure'));
33   }
34
35   public function getTitle()
36   {
37     if ($this->mailer && ($logger = $this->mailer->getLogger()) && $logger->countMessages())
38     {
39       return '<img src="'.$this->webDebug->getOption('image_root_path').'/email.png" alt="Emailer" /> '.$logger->countMessages();
40     }
41   }
42
43   public function getPanelTitle()
44   {
45     return 'Emails';
46   }
47
48   public function getPanelContent()
49   {
50     $logger = $this->mailer->getLogger();
51
52     if (!$logger || !$messages = $logger->getMessages())
53     {
54       return false;
55     }
56
57     $html = array();
58
59     // configuration information
60     $strategy = $this->mailer->getDeliveryStrategy();
61     $html[] = '<h2>Configuration</h2>';
62     $html[] = '<em>Delivery strategy</em>: '.$strategy;
63
64     if (sfMailer::SINGLE_ADDRESS == $strategy)
65     {
66       $html[] = ' - <em>all emails are delivered to</em>: '.$this->mailer->getDeliveryAddress();
67     }
68
69     // email sent
70     $html[] = '<h2>Email sent</h2>';
71     foreach ($messages as $message)
72     {
73       $html[] = $this->renderMessageInformation($message);
74     }
75
76     return implode("\n", $html);
77   }
78
79   protected function renderMessageInformation(Swift_Message $message)
80   {
81     static $i = 0;
82
83     $i++;
84
85     $to = null === $message->getTo() ? '' : implode(', ', array_keys($message->getTo()));
86
87     $html = array();
88     $html[] = sprintf('<h3>%s (to: %s) %s</h3>', $message->getSubject(), $to, $this->getToggler('sfWebDebugMailTemplate'.$i));
89     $html[] = '<div id="sfWebDebugMailTemplate'.$i.'" style="display:'.(1 == $i ? 'block' : 'none').'">';
90     $html[] = '<pre>'.htmlentities($message->toString(), ENT_QUOTES, $message->getCharset()).'</pre>';
91     $html[] = '</div>';
92
93     return implode("\n", $html);
94   }
95
96   /**
97    * Listens for the mailer.configure event and captures a reference to the mailer.
98    *
99    * @param sfEvent $event
100    */
101   public function listenForMailerConfigure(sfEvent $event)
102   {
103     $this->mailer = $event->getSubject();
104   }
105 }
106
Note: See TracBrowser for help on using the browser.