Yaffs site version 1.1
[yaffs-website] / vendor / symfony / event-dispatcher / Debug / WrappedListener.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\EventDispatcher\Debug;
13
14 use Symfony\Component\Stopwatch\Stopwatch;
15 use Symfony\Component\EventDispatcher\Event;
16 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
17
18 /**
19  * @author Fabien Potencier <fabien@symfony.com>
20  */
21 class WrappedListener
22 {
23     private $listener;
24     private $name;
25     private $called;
26     private $stoppedPropagation;
27     private $stopwatch;
28     private $dispatcher;
29
30     public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
31     {
32         $this->listener = $listener;
33         $this->name = $name;
34         $this->stopwatch = $stopwatch;
35         $this->dispatcher = $dispatcher;
36         $this->called = false;
37         $this->stoppedPropagation = false;
38     }
39
40     public function getWrappedListener()
41     {
42         return $this->listener;
43     }
44
45     public function wasCalled()
46     {
47         return $this->called;
48     }
49
50     public function stoppedPropagation()
51     {
52         return $this->stoppedPropagation;
53     }
54
55     public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)
56     {
57         $this->called = true;
58
59         $e = $this->stopwatch->start($this->name, 'event_listener');
60
61         call_user_func($this->listener, $event, $eventName, $this->dispatcher ?: $dispatcher);
62
63         if ($e->isStarted()) {
64             $e->stop();
65         }
66
67         if ($event->isPropagationStopped()) {
68             $this->stoppedPropagation = true;
69         }
70     }
71 }