Skip to content

Commit

Permalink
Prevent duplicate registration of event listeners, fixes #59
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Mar 25, 2016
1 parent c26a5e9 commit 44f9a1f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Logger extends SolariumPlugin implements DataCollectorInterface, \Serializ

private $logger;
private $stopwatch;
private $eventDispatchers = array();

/**
* Plugin init function
Expand All @@ -32,8 +33,11 @@ class Logger extends SolariumPlugin implements DataCollectorInterface, \Serializ
protected function initPluginType()
{
$dispatcher = $this->client->getEventDispatcher();
$dispatcher->addListener(SolariumEvents::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'), 1000);
$dispatcher->addListener(SolariumEvents::POST_EXECUTE_REQUEST, array($this, 'postExecuteRequest'), -1000);
if (!in_array($dispatcher, $this->eventDispatchers, true)) {
$dispatcher->addListener(SolariumEvents::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'), 1000);
$dispatcher->addListener(SolariumEvents::POST_EXECUTE_REQUEST, array($this, 'postExecuteRequest'), -1000);
$this->eventDispatchers[] = $dispatcher;
}
}

/**
Expand Down

0 comments on commit 44f9a1f

Please sign in to comment.