[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * This file is part of the DebugBar package. 4 * 5 * (c) 2013 Maxime Bouroumeau-Fuseau 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 namespace DebugBar\Bridge\SwiftMailer; 12 13 use DebugBar\DataCollector\AssetProvider; 14 use DebugBar\DataCollector\DataCollector; 15 use DebugBar\DataCollector\Renderable; 16 use Swift_Mailer; 17 use Swift_Plugins_MessageLogger; 18 19 /** 20 * Collects data about sent mails 21 * 22 * http://swiftmailer.org/ 23 */ 24 class SwiftMailCollector extends DataCollector implements Renderable, AssetProvider 25 { 26 protected $messagesLogger; 27 28 public function __construct(Swift_Mailer $mailer) 29 { 30 $this->messagesLogger = new Swift_Plugins_MessageLogger(); 31 $mailer->registerPlugin($this->messagesLogger); 32 } 33 34 public function collect() 35 { 36 $mails = array(); 37 foreach ($this->messagesLogger->getMessages() as $msg) { 38 $mails[] = array( 39 'to' => $this->formatTo($msg->getTo()), 40 'subject' => $msg->getSubject(), 41 'headers' => $msg->getHeaders()->toString() 42 ); 43 } 44 return array( 45 'count' => count($mails), 46 'mails' => $mails 47 ); 48 } 49 50 protected function formatTo($to) 51 { 52 if (!$to) { 53 return ''; 54 } 55 56 $f = array(); 57 foreach ($to as $k => $v) { 58 $f[] = (empty($v) ? '' : "$v ") . "<$k>"; 59 } 60 return implode(', ', $f); 61 } 62 63 public function getName() 64 { 65 return 'swiftmailer_mails'; 66 } 67 68 public function getWidgets() 69 { 70 return array( 71 'emails' => array( 72 'icon' => 'inbox', 73 'widget' => 'PhpDebugBar.Widgets.MailsWidget', 74 'map' => 'swiftmailer_mails.mails', 75 'default' => '[]', 76 'title' => 'Mails' 77 ), 78 'emails:badge' => array( 79 'map' => 'swiftmailer_mails.count', 80 'default' => 'null' 81 ) 82 ); 83 } 84 85 public function getAssets() 86 { 87 return array( 88 'css' => 'widgets/mails/widget.css', 89 'js' => 'widgets/mails/widget.js' 90 ); 91 } 92 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |