Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c682f67

Browse files
committed
[HttpKernel] unified the way the traceable event dispatcher injects information into the profiler (closes #5733)
1 parent ee461cb commit c682f67

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232

3333
<service id="data_collector.events" class="%data_collector.events.class%" public="false">
3434
<tag name="data_collector" template="WebProfilerBundle:Collector:events" id="events" priority="255" />
35-
<call method="setEventDispatcher">
36-
<argument type="service" id="event_dispatcher" />
37-
</call>
3835
</service>
3936

4037
<service id="data_collector.logger" class="%data_collector.logger.class%" public="false">

src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
17-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1817

1918
/**
2019
* EventDataCollector.
@@ -23,26 +22,29 @@
2322
*/
2423
class EventDataCollector extends DataCollector
2524
{
26-
private $dispatcher;
27-
28-
public function setEventDispatcher(EventDispatcherInterface $dispatcher)
29-
{
30-
if ($dispatcher instanceof TraceableEventDispatcherInterface) {
31-
$this->dispatcher = $dispatcher;
32-
}
33-
}
34-
3525
/**
3626
* {@inheritdoc}
3727
*/
3828
public function collect(Request $request, Response $response, \Exception $exception = null)
3929
{
4030
$this->data = array(
41-
'called_listeners' => null !== $this->dispatcher ? $this->dispatcher->getCalledListeners() : array(),
42-
'not_called_listeners' => null !== $this->dispatcher ? $this->dispatcher->getNotCalledListeners() : array(),
31+
'called_listeners' => array(),
32+
'not_called_listeners' => array(),
4333
);
4434
}
4535

36+
/**
37+
* Sets the called listeners.
38+
*
39+
* @param array $listeners An array of called listeners
40+
*
41+
* @see TraceableEventDispatcherInterface
42+
*/
43+
public function setCalledListeners(array $listeners)
44+
{
45+
$this->data['called_listeners'] = $listeners;
46+
}
47+
4648
/**
4749
* Gets the called listeners.
4850
*
@@ -55,6 +57,18 @@ public function getCalledListeners()
5557
return $this->data['called_listeners'];
5658
}
5759

60+
/**
61+
* Sets the not called listeners.
62+
*
63+
* @param array $listeners An array of not called listeners
64+
*
65+
* @see TraceableEventDispatcherInterface
66+
*/
67+
public function setNotCalledListeners(array $listeners)
68+
{
69+
$this->data['not_called_listeners'] = $listeners;
70+
}
71+
5872
/**
5973
* Gets the not called listeners.
6074
*

src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,23 +318,25 @@ private function updateProfiles($token, $updateChildren)
318318
return;
319319
}
320320

321-
$this->saveStopwatchInfoInProfile($profile, $updateChildren);
321+
$this->saveInfoInProfile($profile, $updateChildren);
322322
}
323323

324324
/**
325-
* Update the profiles with the timing info and saves them.
325+
* Update the profiles with the timing and events information and saves them.
326326
*
327327
* @param Profile $profile The root profile
328328
* @param Boolean $updateChildren Whether to update the children altogether
329329
*/
330-
private function saveStopwatchInfoInProfile(Profile $profile, $updateChildren)
330+
private function saveInfoInProfile(Profile $profile, $updateChildren)
331331
{
332332
$profile->getCollector('time')->setEvents($this->stopwatch->getSectionEvents($profile->getToken()));
333+
$profile->getCollector('events')->setCalledListeners($this->getCalledListeners());
334+
$profile->getCollector('events')->setNotCalledListeners($this->getNotCalledListeners());
333335
$this->profiler->saveProfile($profile);
334336

335337
if ($updateChildren) {
336338
foreach ($profile->getChildren() as $child) {
337-
$this->saveStopwatchInfoInProfile($child, true);
339+
$this->saveInfoInProfile($child, true);
338340
}
339341
}
340342
}

0 commit comments

Comments
 (0)