Skip to content

Commit

Permalink
[HttpKernel] unified the way the traceable event dispatcher injects i…
Browse files Browse the repository at this point in the history
…nformation into the profiler (closes symfony#5733)
  • Loading branch information
fabpot committed Oct 13, 2012
1 parent ee461cb commit c682f67
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@

<service id="data_collector.events" class="%data_collector.events.class%" public="false">
<tag name="data_collector" template="WebProfilerBundle:Collector:events" id="events" priority="255" />
<call method="setEventDispatcher">
<argument type="service" id="event_dispatcher" />
</call>
</service>

<service id="data_collector.logger" class="%data_collector.logger.class%" public="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* EventDataCollector.
Expand All @@ -23,26 +22,29 @@
*/
class EventDataCollector extends DataCollector
{
private $dispatcher;

public function setEventDispatcher(EventDispatcherInterface $dispatcher)
{
if ($dispatcher instanceof TraceableEventDispatcherInterface) {
$this->dispatcher = $dispatcher;
}
}

/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data = array(
'called_listeners' => null !== $this->dispatcher ? $this->dispatcher->getCalledListeners() : array(),
'not_called_listeners' => null !== $this->dispatcher ? $this->dispatcher->getNotCalledListeners() : array(),
'called_listeners' => array(),
'not_called_listeners' => array(),
);
}

/**
* Sets the called listeners.
*
* @param array $listeners An array of called listeners
*
* @see TraceableEventDispatcherInterface
*/
public function setCalledListeners(array $listeners)
{
$this->data['called_listeners'] = $listeners;
}

/**
* Gets the called listeners.
*
Expand All @@ -55,6 +57,18 @@ public function getCalledListeners()
return $this->data['called_listeners'];
}

/**
* Sets the not called listeners.
*
* @param array $listeners An array of not called listeners
*
* @see TraceableEventDispatcherInterface
*/
public function setNotCalledListeners(array $listeners)
{
$this->data['not_called_listeners'] = $listeners;
}

/**
* Gets the not called listeners.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,23 +318,25 @@ private function updateProfiles($token, $updateChildren)
return;
}

$this->saveStopwatchInfoInProfile($profile, $updateChildren);
$this->saveInfoInProfile($profile, $updateChildren);
}

/**
* Update the profiles with the timing info and saves them.
* Update the profiles with the timing and events information and saves them.
*
* @param Profile $profile The root profile
* @param Boolean $updateChildren Whether to update the children altogether
*/
private function saveStopwatchInfoInProfile(Profile $profile, $updateChildren)
private function saveInfoInProfile(Profile $profile, $updateChildren)
{
$profile->getCollector('time')->setEvents($this->stopwatch->getSectionEvents($profile->getToken()));
$profile->getCollector('events')->setCalledListeners($this->getCalledListeners());
$profile->getCollector('events')->setNotCalledListeners($this->getNotCalledListeners());
$this->profiler->saveProfile($profile);

if ($updateChildren) {
foreach ($profile->getChildren() as $child) {
$this->saveStopwatchInfoInProfile($child, true);
$this->saveInfoInProfile($child, true);
}
}
}
Expand Down

0 comments on commit c682f67

Please sign in to comment.