Ver código fonte

Merge remote branch 'dator/swiftmailer_profiler'

Fabien Potencier 14 anos atrás
pai
commit
b479116e50

+ 58 - 0
src/Symfony/Bundle/SwiftmailerBundle/DataCollector/MessageDataCollector.php

@@ -0,0 +1,58 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bundle\SwiftmailerBundle\DataCollector;
+
+use Symfony\Component\HttpKernel\DataCollector\DataCollector;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * MessageDataCollector.
+ *
+ * @author Clément JOBEILI <clement.jobeili@gmail.com>
+ */
+class MessageDataCollector extends DataCollector
+{
+    protected $logger;
+    
+    public function __construct(\Swift_Events_SendListener $logger)
+    {
+        $this->logger = $logger;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function collect(Request $request, Response $response, \Exception $exception = null)
+    {
+        $this->data['messages'] = $this->logger->getMessages();
+        $this->data['messageCount'] = $this->logger->countMessages();
+    }
+    
+    public function getMessageCount()
+    {
+        return $this->data['messageCount'];
+    }
+
+    public function getMessages()
+    {
+        return $this->data['messages'];
+    }
+    
+    /**
+     * {@inheritdoc}
+     */
+    public function getName()
+    {
+        return 'message';
+    }
+}

+ 2 - 0
src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php

@@ -93,6 +93,8 @@ class SwiftmailerExtension extends Extension
             }
         }
 
+        $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.messagelogger')));
+
         if (isset($config['delivery_address']) && $config['delivery_address']) {
             $container->setParameter('swiftmailer.single_address', $config['delivery_address']);
             $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.redirecting')));

+ 77 - 0
src/Symfony/Bundle/SwiftmailerBundle/Logger/MessageLogger.php

@@ -0,0 +1,77 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bundle\SwiftmailerBundle\Logger;
+
+use Symfony\Component\EventDispatcher\Event;
+
+/**
+ * MessageLogger.
+ *
+ * @author Clément JOBEILI <clement.jobeili@gmail.com>
+ */
+class MessageLogger implements \Swift_Events_SendListener
+{
+
+    /**
+     * @var array
+     */
+    protected $messages;
+
+    public function __construct()
+    {
+        $this->messages = array();   
+    }
+
+    /**
+     * Get the message list
+     *
+     * @return array
+     */
+    public function getMessages()
+    {
+        return $this->messages;
+    }
+
+    /**
+     * Get the message count
+     *
+     * @return int count
+     */
+    public function countMessages()
+    {
+        return count($this->messages);
+    }
+    
+    /**
+     * Empty the message list
+     * 
+     */
+    public function clear()
+    {
+        $this->messages = array();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function beforeSendPerformed(\Swift_Events_SendEvent $evt)
+    {
+        $this->messages[] = $message = clone $evt->getMessage();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function sendPerformed(\Swift_Events_SendEvent $evt)
+    {
+    }
+}

+ 9 - 0
src/Symfony/Bundle/SwiftmailerBundle/Resources/config/swiftmailer.xml

@@ -16,6 +16,8 @@
 
     <parameter key="swiftmailer.plugin.redirecting.class">Swift_Plugins_RedirectingPlugin</parameter>
     <parameter key="swiftmailer.plugin.blackhole.class">Swift_Plugins_BlackholePlugin</parameter>
+    <parameter key="swiftmailer.plugin.messagelogger.class">Symfony\Bundle\SwiftmailerBundle\Logger\MessageLogger</parameter>
+    <parameter key="swiftmailer.data_collector.class">Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector</parameter>
   </parameters>
 
   <services>
@@ -64,6 +66,13 @@
 
     <service id="swiftmailer.plugin.blackhole" class="%swiftmailer.plugin.blackhole.class%" public="false" />
 
+    <service id="swiftmailer.plugin.messagelogger" class="%swiftmailer.plugin.messagelogger.class%" public="false" />
+
+    <service id="swiftmailer.data_collector" class="%swiftmailer.data_collector.class%" public="false">
+        <tag name="data_collector" template="SwiftmailerBundle:Collector:message" id="message" />
+        <argument type="service" id="swiftmailer.plugin.messagelogger" />
+    </service>
+
     <service id="swiftmailer.transport" alias="swiftmailer.transport.smtp" public="false" />
   </services>
 </container>

BIN
src/Symfony/Bundle/SwiftmailerBundle/Resources/public/images/mail.png


Diferenças do arquivo suprimidas por serem muito extensas
+ 95 - 0
src/Symfony/Bundle/SwiftmailerBundle/Resources/views/Collector/message.html.twig