1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Werkspot\Bundle\StatsdBundle\Event; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; |
6
|
|
|
use Symfony\Component\EventDispatcher\Event; |
7
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
8
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
9
|
|
|
use Werkspot\Bundle\StatsdBundle\Client\StatsdClientInterface; |
10
|
|
|
|
11
|
|
|
class RecordingDispatcher implements EventDispatcherInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var ContainerAwareEventDispatcher|EventDispatcherInterface |
15
|
|
|
*/ |
16
|
|
|
private $originalDispatcher; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var StatsdClientInterface |
20
|
|
|
*/ |
21
|
|
|
private $statsdClient; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param EventDispatcherInterface $originalDispatcher |
25
|
|
|
* @param StatsdClientInterface $statsdClient |
26
|
|
|
*/ |
27
|
|
|
public function __construct( |
28
|
|
|
EventDispatcherInterface $originalDispatcher, |
29
|
|
|
StatsdClientInterface $statsdClient |
30
|
|
|
) { |
31
|
|
|
$this->originalDispatcher = $originalDispatcher; |
32
|
|
|
$this->statsdClient = $statsdClient; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @see ContainerAwareEventDispatcher::addListenerService |
37
|
|
|
*/ |
38
|
|
|
public function addListenerService($eventName, $callback, $priority = 0) |
39
|
|
|
{ |
40
|
|
|
$this->originalDispatcher->addListenerService($eventName, $callback, $priority); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @see ContainerAwareEventDispatcher::addSubscriberService |
45
|
|
|
*/ |
46
|
|
|
public function addSubscriberService($serviceId, $class) |
47
|
|
|
{ |
48
|
|
|
$this->originalDispatcher->addSubscriberService($serviceId, $class); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function dispatch($eventName, Event $event = null) |
55
|
|
|
{ |
56
|
|
|
$this->statsdClient->increment(str_replace('.', '-', $eventName)); |
57
|
|
|
return $this->originalDispatcher->dispatch($eventName, $event); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function addListener($eventName, $listener, $priority = 0) |
64
|
|
|
{ |
65
|
|
|
$this->originalDispatcher->addListener($eventName, $listener, $priority); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function addSubscriber(EventSubscriberInterface $subscriber) |
72
|
|
|
{ |
73
|
|
|
$this->originalDispatcher->addSubscriber($subscriber); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
public function removeListener($eventName, $listener) |
80
|
|
|
{ |
81
|
|
|
$this->originalDispatcher->removeListener($eventName, $listener); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function removeSubscriber(EventSubscriberInterface $subscriber) |
88
|
|
|
{ |
89
|
|
|
$this->originalDispatcher->removeSubscriber($subscriber); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
|
|
public function getListeners($eventName = null) |
96
|
|
|
{ |
97
|
|
|
return $this->originalDispatcher->getListeners($eventName); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function hasListeners($eventName = null) |
104
|
|
|
{ |
105
|
|
|
return $this->originalDispatcher->hasListeners($eventName); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
|
|
public function getListenerPriority($eventName, $listener) |
112
|
|
|
{ |
113
|
|
|
return $this->getListenerPriority($eventName, $listener); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: