MessageDataCollector.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  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. namespace Symfony\Bundle\SwiftmailerBundle\DataCollector;
  11. use Symfony\Component\HttpKernel\DataCollector\DataCollector;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. /**
  15. * MessageDataCollector.
  16. *
  17. * @author Clément JOBEILI <clement.jobeili@gmail.com>
  18. */
  19. class MessageDataCollector extends DataCollector
  20. {
  21. protected $logger;
  22. public function __construct(\Swift_Events_SendListener $logger)
  23. {
  24. $this->logger = $logger;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function collect(Request $request, Response $response, \Exception $exception = null)
  30. {
  31. $this->data['messages'] = $this->logger->getMessages();
  32. $this->data['messageCount'] = $this->logger->countMessages();
  33. }
  34. public function getMessageCount()
  35. {
  36. return $this->data['messageCount'];
  37. }
  38. public function getMessages()
  39. {
  40. return $this->data['messages'];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function getName()
  46. {
  47. return 'message';
  48. }
  49. }