-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #10200 [EventDispatcher] simplified code for TraceableEventDi…
…spatcher (fabpot) This PR was merged into the 2.5-dev branch. Discussion ---------- [EventDispatcher] simplified code for TraceableEventDispatcher | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 42e4c7b [EventDispatcher] simplified code for TraceableEventDispatcher
- Loading branch information
Showing
3 changed files
with
146 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\EventDispatcher\Debug; | ||
|
||
use Symfony\Component\Stopwatch\Stopwatch; | ||
use Symfony\Component\EventDispatcher\Event; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class WrappedListener | ||
{ | ||
private $listener; | ||
private $name; | ||
private $called; | ||
private $stoppedPropagation; | ||
private $stopwatch; | ||
|
||
public function __construct($listener, $name, Stopwatch $stopwatch) | ||
{ | ||
$this->listener = $listener; | ||
$this->name = $name; | ||
$this->stopwatch = $stopwatch; | ||
$this->called = false; | ||
$this->stoppedPropagation = false; | ||
} | ||
|
||
public function getWrappedListener() | ||
{ | ||
return $this->listener; | ||
} | ||
|
||
public function wasCalled() | ||
{ | ||
return $this->called; | ||
} | ||
|
||
public function stoppedPropagation() | ||
{ | ||
return $this->stoppedPropagation; | ||
} | ||
|
||
public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher) | ||
{ | ||
$this->called = true; | ||
|
||
$e = $this->stopwatch->start($this->name, 'event_listener'); | ||
|
||
call_user_func($this->listener, $event, $eventName, $dispatcher); | ||
|
||
if ($e->isStarted()) { | ||
$e->stop(); | ||
} | ||
|
||
if ($event->isPropagationStopped()) { | ||
$this->stoppedPropagation = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters