Drupal investigation

EventDataCollector.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\HttpKernel\DataCollector;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
  15. /**
  16. * EventDataCollector.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class EventDataCollector extends DataCollector implements LateDataCollectorInterface
  21. {
  22. protected $dispatcher;
  23. public function __construct(EventDispatcherInterface $dispatcher = null)
  24. {
  25. $this->dispatcher = $dispatcher;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function collect(Request $request, Response $response, \Exception $exception = null)
  31. {
  32. $this->data = array(
  33. 'called_listeners' => array(),
  34. 'not_called_listeners' => array(),
  35. );
  36. }
  37. public function lateCollect()
  38. {
  39. if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
  40. $this->setCalledListeners($this->dispatcher->getCalledListeners());
  41. $this->setNotCalledListeners($this->dispatcher->getNotCalledListeners());
  42. }
  43. }
  44. /**
  45. * Sets the called listeners.
  46. *
  47. * @param array $listeners An array of called listeners
  48. *
  49. * @see TraceableEventDispatcherInterface
  50. */
  51. public function setCalledListeners(array $listeners)
  52. {
  53. $this->data['called_listeners'] = $listeners;
  54. }
  55. /**
  56. * Gets the called listeners.
  57. *
  58. * @return array An array of called listeners
  59. *
  60. * @see TraceableEventDispatcherInterface
  61. */
  62. public function getCalledListeners()
  63. {
  64. return $this->data['called_listeners'];
  65. }
  66. /**
  67. * Sets the not called listeners.
  68. *
  69. * @param array $listeners An array of not called listeners
  70. *
  71. * @see TraceableEventDispatcherInterface
  72. */
  73. public function setNotCalledListeners(array $listeners)
  74. {
  75. $this->data['not_called_listeners'] = $listeners;
  76. }
  77. /**
  78. * Gets the not called listeners.
  79. *
  80. * @return array An array of not called listeners
  81. *
  82. * @see TraceableEventDispatcherInterface
  83. */
  84. public function getNotCalledListeners()
  85. {
  86. return $this->data['not_called_listeners'];
  87. }
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public function getName()
  92. {
  93. return 'events';
  94. }
  95. }