NotificationDataCollector.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\Component\Notifier\DataCollector;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpKernel\DataCollector\DataCollector;
  14. use Symfony\Component\Notifier\Event\NotificationEvents;
  15. use Symfony\Component\Notifier\EventListener\NotificationLoggerListener;
  16. /**
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. *
  19. * @experimental in 5.1
  20. */
  21. final class NotificationDataCollector extends DataCollector
  22. {
  23. private $logger;
  24. public function __construct(NotificationLoggerListener $logger)
  25. {
  26. $this->logger = $logger;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function collect(Request $request, Response $response, \Throwable $exception = null)
  32. {
  33. $this->data['events'] = $this->logger->getEvents();
  34. }
  35. public function getEvents(): NotificationEvents
  36. {
  37. return $this->data['events'];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function reset()
  43. {
  44. $this->data = [];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function getName()
  50. {
  51. return 'notifier';
  52. }
  53. }