Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

EventDataCollector.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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\EventDispatcher\Debug\TraceableEventDispatcher;
  12. use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\RequestStack;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  17. use Symfony\Contracts\Service\ResetInterface;
  18. /**
  19. * EventDataCollector.
  20. *
  21. * @author Fabien Potencier <fabien@symfony.com>
  22. */
  23. class EventDataCollector extends DataCollector implements LateDataCollectorInterface
  24. {
  25. protected $dispatcher;
  26. private $requestStack;
  27. private $currentRequest;
  28. public function __construct(EventDispatcherInterface $dispatcher = null, RequestStack $requestStack = null)
  29. {
  30. $this->dispatcher = $dispatcher;
  31. $this->requestStack = $requestStack;
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function collect(Request $request, Response $response, \Exception $exception = null)
  37. {
  38. $this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
  39. $this->data = [
  40. 'called_listeners' => [],
  41. 'not_called_listeners' => [],
  42. 'orphaned_events' => [],
  43. ];
  44. }
  45. public function reset()
  46. {
  47. $this->data = [];
  48. if ($this->dispatcher instanceof ResetInterface) {
  49. $this->dispatcher->reset();
  50. }
  51. }
  52. public function lateCollect()
  53. {
  54. if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
  55. $this->setCalledListeners($this->dispatcher->getCalledListeners($this->currentRequest));
  56. $this->setNotCalledListeners($this->dispatcher->getNotCalledListeners($this->currentRequest));
  57. }
  58. if ($this->dispatcher instanceof TraceableEventDispatcher) {
  59. $this->setOrphanedEvents($this->dispatcher->getOrphanedEvents($this->currentRequest));
  60. }
  61. $this->data = $this->cloneVar($this->data);
  62. }
  63. /**
  64. * Sets the called listeners.
  65. *
  66. * @param array $listeners An array of called listeners
  67. *
  68. * @see TraceableEventDispatcher
  69. */
  70. public function setCalledListeners(array $listeners)
  71. {
  72. $this->data['called_listeners'] = $listeners;
  73. }
  74. /**
  75. * Gets the called listeners.
  76. *
  77. * @return array An array of called listeners
  78. *
  79. * @see TraceableEventDispatcher
  80. */
  81. public function getCalledListeners()
  82. {
  83. return $this->data['called_listeners'];
  84. }
  85. /**
  86. * Sets the not called listeners.
  87. *
  88. * @param array $listeners
  89. *
  90. * @see TraceableEventDispatcher
  91. */
  92. public function setNotCalledListeners(array $listeners)
  93. {
  94. $this->data['not_called_listeners'] = $listeners;
  95. }
  96. /**
  97. * Gets the not called listeners.
  98. *
  99. * @return array
  100. *
  101. * @see TraceableEventDispatcher
  102. */
  103. public function getNotCalledListeners()
  104. {
  105. return $this->data['not_called_listeners'];
  106. }
  107. /**
  108. * Sets the orphaned events.
  109. *
  110. * @param array $events An array of orphaned events
  111. *
  112. * @see TraceableEventDispatcher
  113. */
  114. public function setOrphanedEvents(array $events)
  115. {
  116. $this->data['orphaned_events'] = $events;
  117. }
  118. /**
  119. * Gets the orphaned events.
  120. *
  121. * @return array An array of orphaned events
  122. *
  123. * @see TraceableEventDispatcher
  124. */
  125. public function getOrphanedEvents()
  126. {
  127. return $this->data['orphaned_events'];
  128. }
  129. /**
  130. * {@inheritdoc}
  131. */
  132. public function getName()
  133. {
  134. return 'events';
  135. }
  136. }